- 浏览: 126936 次
- 性别:
- 来自: 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 904java.util.concurrent.CyclicBarr ... -
Delayed interface and Delay Queue
2009-04-22 17:42 1053/** * A standard implementati ... -
3 ways to break dead lock
2009-04-21 17:30 7621) supply special resources. ... -
Blocking Queue Usage
2009-04-20 11:21 8333 implementations: LinkedBlocki ... -
The usage of Lock and Condition
2009-04-18 12:31 1069//: concurrency/waxomatic2/WaxO ... -
Re entrantLock usage
2009-04-15 17:15 1320a thread can be really interru ... -
new interrupt in java5
2009-04-15 12:08 658In Java 5, Thread.interrupt() i ... -
interrupt
2009-04-15 10:57 8171) Each thread has a boolean in ... -
Executor Service Usage
2009-04-14 18:18 894ExecutorService exec = Executor ... -
Thread Local usage
2009-04-14 17:46 817ThreadLocal usage – from Javado ... -
Timer TimerTask usage
2009-04-14 12:03 724Timer typical usage new Tim ... -
wait, notify及线程通讯机制
2009-02-26 22:42 8501) wait(), notify() 方法被调用的时候,只要 ... -
Java Thread programming basical knowledge
2009-02-26 22:40 1089yield() : Give a hint to the th ... -
Count Down Latch explanation
2008-10-02 10:29 957Very important paragraph on how ... -
Scheduled Executor Service
2008-07-22 11:27 1106Executor can return Executor, E ... -
Executor usage
2008-07-22 11:04 903Executor is used to arrange thr ... -
Callable Usage
2008-07-22 10:24 933The important thing need to loo ...
相关推荐
在`countdownlatch-example-sourcecode.zip`这个压缩包中,我们可以看到一些关于CountDownLatch实际应用的示例代码。本文将深入探讨CountDownLatch的工作原理、使用方法以及它在并发编程中的应用场景。 1. **...
source code for 4 channel rf remote controled home automation
Latch SPIN_COUNT 参数(在Oracle 7中称为_LATCH_SPIN_COUNT)用于控制进程在等待Latch时的自旋次数。合理设置该参数可以帮助减少上下文切换开销,提高系统性能。根据系统的具体需求调整该参数是非常重要的。 总之...
"Latch up测试标准" Latch up测试标准是JEDEC(Joint Electron Device Engineering Council)制定的一个工业标准,旨在确保半导体器件的可靠性和安全性。Latch up是一种电流泄露现象,当半导体器件在高温、高湿或...
- **调整并发控制参数**:根据实际情况调整与并发控制相关的参数,如`_spin_count`,可以优化Latch的获取策略,减少不必要的等待时间。 - **优化SQL语句和应用程序逻辑**:避免不必要的数据锁定和过度的并发访问,...
SELECT COUNT(*) number_of_waiters FROM v$session_wait w, v$latch l WHERE w.wait_time = 0 -- 当前正在等待的会话 AND w.event = 'latch free' AND w.p2 = l.latch# AND l.name LIKE 'library%'; ``` 通过...
### Latch Type与滞回比较器详解 #### Latch Type结构概述 在高速信号处理领域,比较器的设计至关重要。为了满足更高的速度需求,除了通过增加电路中的工作电流来提升响应速度这一传统方法之外,另一种有效手段是...
Oracle数据库中的"Latch Free"等待事件是数据库性能优化的一个重要概念。在深入探讨这个主题之前,我们先要理解什么是Latch和Lock,以及它们之间的区别。 Latch(锁片或轻量级锁)是一种低级别的同步机制,主要用于...
"Latch up 的原理分析" Latch up 是一种常见的集成电路故障,发生在 CMOS 芯片中,是由于寄生PNP和NPN双极性BJT之间的相互影响而产生的一低阻抗通路。Latch up 的出现可能会使 VDD 和 GND 之间产生大电流,导致芯片...
【学习动态性能表(11)--v$latch$v$latch_children】主要关注Oracle数据库中的动态性能视图,尤其是关于latch这一关键概念的监控和分析。latch是一种轻量级的锁定机制,用于保护SGA(System Global Area)中的共享...
Oracle数据库是一种广泛使用的大型关系型数据库管理系统,它在处理并发事务时采用了一种称为“Latch”和“Lock”的并发控制机制。Latch(闩锁)和Lock(锁定)都是Oracle用来确保数据一致性、防止数据冲突的关键组件...
### FPGA中Latch简介 #### 一、什么是Latch? 在FPGA设计中,Latch(锁存器)是一种在异步时序电路系统中使用的存储单元,它对输入信号的电平敏感,用于存储信息。通常情况下,一个锁存器能够存储1比特的信息。...
Oracle通过一个隐含参数`_kghdsidx_count`来控制子共享池的数量。增加子共享池的数目可以提高并发性能,但同时也需要相应的内存资源。每个子共享池都有其独立的LRU(Least Recently Used)列表和Shared Pool Latch。...
### CMOS Latchup详解 #### 一、引言 《关于CMOS Latchup的书》是由Steven H. Voldman所著的一本专业书籍,该书详细介绍了CMOS技术中的Latchup现象及其相关解决方案。Latchup是集成电路设计与制造过程中一个非常...
在Oracle数据库系统中,了解和区分Latch(锁存器)和Lock(锁)是非常重要的,因为它们都是数据库并发控制的关键机制,确保数据的一致性和完整性。以下是对这两个概念的详细解释: 1. Latch(锁存器) - 目的:...
《芯片LATCHUP原理详解及防范措施》 LATCHUP,又称闩锁效应,是集成电路设计中一个重要的问题,尤其对于CMOS工艺的芯片来说,它可能导致芯片功能失效甚至损坏。本文将深入探讨LATCHUP的产生原理以及如何有效地防止...
标题与描述:“Latch_Lock_And_Mutex_Contention_Troubleshooting” 知识点详述: ### 1. Latch机制概述 Latch是Oracle数据库中用于管理内存结构并发访问的一种低级机制,主要用于保护短暂访问的内存结构,如缓存...
在Laravel框架中,"Laravel Latch"是一个用于处理会话、认证和授权的工具,它增强了Laravel原生的安全特性。Latch的核心概念是提供了一种更简单的方式来管理和控制用户状态,确保应用程序的数据安全性和用户体验。在...
静电放电(Electrostatic Discharge,简称ESD)与闩锁效应(Latch-Up)是集成电路设计与制造中两个至关重要的问题,它们直接关系到电路的可靠性和使用寿命。以下是对这两个概念及其相互关联的深入探讨。 ### 静电...