- 浏览: 121404 次
- 性别:
- 来自: Singapore
文章分类
- 全部博客 (112)
- Tiger Thread (18)
- Perforce (6)
- Spring (5)
- maven (3)
- log4j (3)
- Quartz Scheduler (4)
- unix and linux (12)
- hibernate (3)
- Enum (1)
- Futures and Options (1)
- Market Making (2)
- Java Basic (11)
- Tibco EMS (3)
- F I X message (5)
- equity derivative (2)
- Sybase (3)
- XML (1)
- JUnit (2)
- J A X B 2.0 (1)
- N I O (1)
- windows batch file (1)
- Cruise Control (1)
- util Class (5)
- ant (1)
- JMS (1)
- profiling (0)
- Sql Server (6)
- GXT (2)
- eclipse (1)
- Generics (1)
- Tibco RV (3)
- Autosys (0)
- Message (1)
最新评论
-
houzhe11:
<property name="proxyTa ...
AOP usage -- BeanNameAutoProxyCreator usage
a thread can be really interrupted by aThread.interrupt() only under 1 situation -- in blocked status wrapped with catch(InterruptedException e) {...}. Precisely,
a) aThread.sleep();
b) aObject.wait();
c) BlockingQueue operations;
d) Lock.lockInterruptibly();
Regarding d). When a thread is waiting outside of some lock, previously, you can't interrupt it, the thread will just block there if he can not get the lock --- dead lock.
In Java 5, Lock.lockInterruptibly() needs to be wrapped with InterruptedException, which means you can save the thread from stupid waiting.
=====Code example ======
public static void main(String[] args)
{
Thread i1 = new Thread(new RunIt3());
Thread i2 = new Thread(new RunIt3());
i1.start();
i2.start();
i2.interrupt();
}
class RunIt3 implements Runnable
{
private static Lock lock = new ReentrantLock();
public void run()
{
try
{
lock.lock();
//lock.lockInterruptibly(); ---- c)
System.out.println(Thread.currentThread().getName() + " running");
TimeUnit.SECONDS.sleep(20); ----- b)
lock.unlock();
System.out.println(Thread.currentThread().getName() + " finished");
}
catch (InterruptedException e)
{
System.out.println(Thread.currentThread().getName() + " interrupted");
}
}
}
---Output---
Thread-0 running ---- a)
Thread-0 finished
Thread-1 running
Thread-1 interrupted
Explain:
a) Actually at here, thread1 has already been interrupted. But thread1 has to wait 20 seconds later, till thread0 has finished running, and thread1 goes to place b), at that place, thread1 can goto catch block! That’s quite late!
If you change from lock.lock() to lock.lockInterruptibly()
---Output---
Thread-0 running
Thread-1 interrupted
Thread-0 finished
Because c) has been monitored with InterruptedException, when thread0 is working, thread1 is waiting outside of lock, if you interrupt thread1, thread1 will immediately goes to catch block.
发表评论
-
javadoc for Cyclic Barrier
2009-04-24 12:48 848java.util.concurrent.CyclicBarr ... -
Delayed interface and Delay Queue
2009-04-22 17:42 1000/** * A standard implementati ... -
Count Down Latch example code
2009-04-22 10:38 1089Key point : 1) 1 task is co ... -
3 ways to break dead lock
2009-04-21 17:30 7031) supply special resources. ... -
Blocking Queue Usage
2009-04-20 11:21 7943 implementations: LinkedBlocki ... -
The usage of Lock and Condition
2009-04-18 12:31 1038//: concurrency/waxomatic2/WaxO ... -
new interrupt in java5
2009-04-15 12:08 634In Java 5, Thread.interrupt() i ... -
interrupt
2009-04-15 10:57 7641) Each thread has a boolean in ... -
Executor Service Usage
2009-04-14 18:18 861ExecutorService exec = Executor ... -
Thread Local usage
2009-04-14 17:46 760ThreadLocal usage – from Javado ... -
Timer TimerTask usage
2009-04-14 12:03 688Timer typical usage new Tim ... -
wait, notify及线程通讯机制
2009-02-26 22:42 8041) wait(), notify() 方法被调用的时候,只要 ... -
Java Thread programming basical knowledge
2009-02-26 22:40 925yield() : Give a hint to the th ... -
Count Down Latch explanation
2008-10-02 10:29 897Very important paragraph on how ... -
Scheduled Executor Service
2008-07-22 11:27 1060Executor can return Executor, E ... -
Executor usage
2008-07-22 11:04 843Executor is used to arrange thr ... -
Callable Usage
2008-07-22 10:24 884The important thing need to loo ...
相关推荐
[1] and the 2015 fourth edition, re-titled Fowler's Dictionary of Modern English Usage, edited by Jeremy Butterfield, takes the same approach as the third edition (and only revised some entries)....
Universal Serial Bus HID Usage TablesUniversal Serial Bus HID Usage Tables
Android 使用记录访问权限(PACKAGE_USAGE_STATS)、UsageStatsManagerAndroid 使用记录访问权限(PACKAGE_USAGE_STATS)、UsageStatsManagerAndroid 使用记录访问权限(PACKAGE_USAGE_STATS)、...
CSS Usage.xpi CSS减肥工具Firefox插件CSS Usage使用教程.txt firebug-2.0.16-fx.xpi Firefox Setup 30.0b9.exe
css usage是一个基于firebug的firefox扩展,可以用来查看页面中的CSS的使用情况,可以清楚的查看css文件中所有的规则在你的网站中的 真实的使用情况。可以查看一个网站中多个页面中的css使用情况——这个很好,可以...
USB HID usage tableUSB键值,可以下来看看
HID-Usage-Tables-v1.12的中文版本,刚刚借助翻译狗网站翻译过来,希望对要深入了解的同学有帮助
第一步,我们需要安装Firefox,或者确定你...第四步,在浏览器中打开我们要优化的页面(本地的页面也可以),点击右下角的firebug小图标,打开firebug工具窗口,我们会看到在工具选项中我们有一个 CSS Usage工具的按钮。
802.11ac usage model,ppt,英文
Usage search for ALL types of assets, e.g.: Scripts, Shaders, Scenes, Materials, Sprites, Prefabs, Fonts, Textures, Sounds... Search for usages in: Prefabs, Scenes, Atlases, Materials and others ...
Usage of A4J.Usage of A4J.Usage of A4J.
hid usage table version 1.1官方标准文件
第四步,在Firefox浏览器中打开我们要优化的页面(本地的页面也可以),点击右上角的firebug(有个小蜜蜂图标),打开firebug工具窗口,我们会看到在工具选项中我们有一个 CSS Usage工具的按钮。 首先我们来分析最...
创建VS的Web Application读取CPU使用值,并显示在Chart控件上
1996-2022 USB Implementers’ Forum - All rights reserved USB 最新HID Usage Tables 2022
双击CPU Usage.exe即可运行软件,选项中可以选择记录cpu的间隔时间,以毫秒为单位,记录cpu占用率数值,可以将数据导出到指定位置,保存文件为excel文档格式。
Setting Up Usage Tracking in Oracle BIEE
Modern Fortran Style and Usage
SAP HANA Memory Usage Explained.pdf
FireFox_css_usage-0.2.9 过滤网站中没有必要的CSS 简化CSS代码非常方便