- 浏览: 121403 次
- 性别:
- 来自: 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
1) wait(), notify() 方法被调用的时候,只要外面没有被synchronized()罩住,编译可过,但是跑起来一定发生异常--- current thread not owner
2) wait(), notify()的ref1一定要和synchronized(ref2)一致!两个ref必须是同一个东西,否则报错。
3) 处于wait()状态的Thread t1, 如果被别人调用了t1.interrupt(),立刻从wait()状态抛出interrupted异常,由此看来,线程通讯的另一种方法---wait(), interrupt()组合。当等待时间不确定的时候,只需要让某线程wait()在一个本地obj上(保证永远不会被别人notify()起来),然后让外部线程通过interrupt()来唤醒。
public class ThreadTest
{
/**
* @param args
* @throws InterruptedException
*/
public static void main(String[] args) throws InterruptedException
{
ThreadWait t5 = new ThreadWait();
t5.start();
// Doing alot of staff, here, maybe takes around 100ms, have no idea how long it will take.
Thread.sleep(1000);
t5.interrupt();
}
}
class ThreadWait extends Thread
{
public void run()
{
Object obj = new Object();
synchronized (obj)
{
for (int i = 1; i <= 3; i++)
{
System.out.println("ThreadSleep : " + i + ". " + this.getName());
}
try
{
obj.wait();//永远没有机会被notify(),只有等待被interrupt,被interrupt之后,才会继续执行,
//因为我也不知道我要等待多长时间
}
catch (InterruptedException ignore){}
for (int i = 4; i <= 6; i++)
{
System.out.println("ThreadSleep : " + i + ". " + this.getName());
}
}
}
}
发表评论
-
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 ... -
Re entrantLock usage
2009-04-15 17:15 1289a thread can be really interru ... -
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 ... -
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 ...
相关推荐
wait,notify等线程知识.pdf
源码—Java多线程5—死锁和wait notify notifyAll
一个简单的线程同步机制,也能实例了解wait notify的使用,notify与notifyAll的区别
在学习Java过程中,自己收集了很多的Java的学习资料,分享给大家,有需要的欢迎下载,希望对大家有用,一起学习,一起进步。
开一个子线程来完成一个循环处理的工作,我在主线程中能灵活控制这个子线程的开始、暂停/继续、结束。
使用Java多线程的wait和notify方法实现最简单的生产者消费者模式
主线程去控制子线程wait与notify
java多线程之wait,notify的用法([ 详解+实例 ]).
java多线程下wait和notify的作用
在学习Java过程中,自己收集了很多的Java的学习资料,分享给大家,有需要的欢迎下载,希望对大家有用,一起学习,一起进步。
在学习Java过程中,自己收集了很多的Java的学习资料,分享给大家,有需要的欢迎下载,希望对大家有用,一起学习,一起进步。
主要介绍了java多线程wait,notify,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,下面小编和大家一起来学习一下吧
主要介绍了Java多线程通讯之wait,notify的区别详解,非常不错,具有一定的参考借鉴借鉴价值,需要的朋友可以参考下
java中多线程编程notify、wait的使用
一个理解wait()与notify()的例子,让你更好理解.
在学习Java过程中,自己收集了很多的Java的学习资料,分享给大家,有需要的欢迎下载,希望对大家有用,一起学习,一起进步。
Java多线程机制 9.1 Java中的线程 9.2 Thread的子类创建线程 ...9.7 在同步方法中使用wait()、notify 和notifyAll()方法 9.8 挂起、恢复和终止线程 9.9 计时器线程Timer 9.10 线程联合 9.11 守护线程
wait, notify 和 notifyAll,这些在多线程中被经常用到的保留关键字,在实际开发的时候很多时候却并没有被大家重视。本文对这些关键字的使用进行了描述。 在 Java 中可以用 wait、notify 和 notifyAll 来实现...
在学习Java过程中,自己收集了很多的Java的学习资料,分享给大家,有需要的欢迎下载,希望对大家有用,一起学习,一起进步。