Archive for August, 2010
微博客输入框jQuery插件
Aug 29th
自己开发的一个类似微博客输入框的一个jQuery插件,也可以让大家学习下怎么开发一个简单的jQuery插件。
(function($){
$.fn.extend({
speaker:function(countId){
var intervalId = jQuery.data(this, 'intervalId');
this.focus(function(){
if(intervalId==null||intervalId!=0){
intervalId = setInterval("jQuery.speaker.check('"+this.id+"','"+countId+"')",50);
jQuery.data(this, 'intervalId', intervalId);
}
});
this.blur(function(){
var intervalId = jQuery.data(this, 'intervalId');
jQuery.data(this, 'intervalId', 0);
clearInterval(intervalId);
});
}
});
jQuery.extend({
speaker: {
check:function(id,countId){
var str = $("#"+id).val();
var count = 140-str.length;
$("#"+countId).html(count);
if(count>10){
$("#"+countId).attr("style","color:#000000;");
}else if(count>=0){
$("#"+countId).attr("style","color:#085879;");
}else{
$("#"+countId).attr("style","color:#BA2636;");
}
}
}
});
})(jQuery);
ThreadPoolExecutor策略
Aug 27th
ThreadPoolExecutor的策略策略有四种
CallerRunsPolicy【重要的任务】
当异步线程池满了时,使用阻塞式,丢弃异步的方式执行,此策略比较保守,不丢弃,不放弃。
AbortPolicy【不太重要,但需要监控的任务】
中止任务,并抛出异常。
DiscardPolicy【满足最先请求的任务】
丢弃当前线程,也就是新来的任务丢弃掉。
DiscarOldestPolicy【满足最后请求的任务】
丢弃任务列队里最老的线程。
对于ThreadPoolExecutor来说,还有关注的地方是,他有3种列队。
- SynchronousQueue
- LinkedBlockingQueue
- ArrayBlockingQueue