- 浏览: 121414 次
- 性别:
- 来自: 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
Key point :
1) 1 task is composed of several portion.
2) every portion finished, the portion will call latch.countDown()
3) Threads depending on this task will call latch.await()
4) latch will be initialized using portion number, countDown() will decrese the number, when the number reaches 0, latch will release all those threads awaiting the latch open.
Sample code attached.
package concurrency;
//: concurrency/CountDownLatchDemo.java
import static java.lang.System.out;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
// Performs some portion of a task:
class TaskPortion implements Runnable
{
private static int counter = 0;
private final int id = counter++;
private static Random rand = new Random(47);
private final CountDownLatch latch;
TaskPortion(CountDownLatch latch)
{
this.latch = latch;
}
public void run()
{
try
{
doWork();
latch.countDown();
}
catch (InterruptedException ex)
{
// Acceptable way to exit
}
}
public void doWork() throws InterruptedException
{
TimeUnit.MILLISECONDS.sleep(rand.nextInt(2000));
out.println(this + "completed");
}
public String toString()
{
return String.format("%1$-3d ", id);
}
}
// Waits on the CountDownLatch:
class WaitingTask implements Runnable
{
private static int counter = 0;
private final int id = counter++;
private final CountDownLatch latch;
WaitingTask(CountDownLatch latch)
{
this.latch = latch;
}
public void run()
{
try
{
latch.await();
out.println("Latch barrier passed for " + this);
}
catch (InterruptedException ex)
{
out.println(this + " interrupted");
}
}
public String toString()
{
return String.format("WaitingTask %1$-3d ", id);
}
}
public class CountDownLatchDemo
{
static final int SIZE = 100;
public static void main(String[] args) throws Exception
{
ExecutorService exec = Executors.newCachedThreadPool();
// All must share a single CountDownLatch object:
CountDownLatch latch = new CountDownLatch(SIZE);
for (int i = 0; i < 10; i++)
exec.execute(new WaitingTask(latch));
for (int i = 0; i < SIZE; i++)
exec.execute(new TaskPortion(latch));
out.println("Launched all tasks");
exec.shutdown(); // Quit when all tasks complete
}
} /* (Execute to see output) *///:~
发表评论
-
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 ... -
3 ways to break dead lock
2009-04-21 17:30 7041) supply special resources. ... -
Blocking Queue Usage
2009-04-20 11:21 7953 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 1291a 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 ... -
wait, notify及线程通讯机制
2009-02-26 22:42 8041) wait(), notify() 方法被调用的时候,只要 ... -
Java Thread programming basical knowledge
2009-02-26 22:40 926yield() : 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 1061Executor 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 ...
相关推荐
source code for 4 channel rf remote controled home automation
countdownlatch-example-sourcecode.zip
Latch free等待事件 Latch和lock的异同
本文章是关于fpga中latch简介。
latch讲解,latch讲解,绝对经典
Latch up测试标准
国外论文,从最基本的角度讲述latch up原理
LATCH HA解决方案系统结构:两台主机A,B共享一个磁盘阵列,A为工作机,B为备份机。它们之间以一根心跳线来连接,这被称为“心跳检测”,主要通过一条 RS232检测链路来完成。LATCH HA也采用了网络ping检测来验证系统...
Advertisement Latch up .rar (11.21 KB, 下载次数: 441 ) 2010-10-25 13:43 上传 点击文件名下载附件 下载积分: 资产 -2 信元, 下载支出 2 信元 分析
Oracle中的Latch和Lock.pdf
Oracle性能诊断之——Latch free
有关oracle当中锁的描述,Latch和Lock的区别,挺不错的。
oracle latch介绍,介绍的非常非常非常非常非常非常非常非常非常非常非常非常非常好
一般比较器在要求速度较高时除了增大各级工作电流外,还有一种方法就是使用Latch type结构。
- latch是一种Oracle低级别的内存保护机制,用于序列化对于非常短时间的内存结构的并发访问。 - latch是一种简单的内存结构。 - latch的大小通常在100-200B左右(取决于Oracle的版本和Oracle运行的平台)。 - latch...
oracle latch描述以及使用
在很多地方都能看到,verilog中if与case语句必须完整,即if要加上else,case后要加上default语句,以防止锁存器的发生,接下来就来说说其中原因。
图文并茂,解释了latch up产生的原因,并详细介绍了防止latch up 产生的方法
等待事件row cache lock,latch row cache objects处理过程
闩锁效应(latch up)是CMOS必须注意的现象,latch解释为回路更合适,大家以后看到latch up就联想到在NMOS与PMOS里面的回路。 为什么它这么重要?因为它会导致整个芯片的失效,所以latch up是QUAL测试的一种,并且与...