- 浏览: 126928 次
- 性别:
- 来自: 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
Very important paragraph on how the CountDownLatch works. CountDownLatch is a flexible latch implementation that can be used in any of these situations;
it allows one or more threads to wait for a set of events to occur. The latch state consists of a counter initialized
to a positive number, representing the number of events to wait for. The countDown method decrements the counter,
indicating that an event has occurred, and the await methods wait for the counter to reach zero, which happens
when all the events have occurred. If the counter is nonzero on entry, await blocks until the counter reaches zero,
the waiting thread is interrupted, or the wait times out.
The following 2 paragraphs are very important on explaining an example how we use CountDownLatch TestHarness illustrates two common uses for latches. TestHarness creates a number of threads
that run a given task concurrently. It uses two latches, a "starting gate" and an "ending gate". The starting gate is
initialized with a count of one; the ending gate is initialized with a count equal to the number of worker threads.
The first thing each worker thread does is wait on the starting gate; this ensures that none of them starts working
until they all are ready to start. The last thing each does is count down on the ending gate; this allows the master
thread to wait efficiently until the last of the worker threads has finished, so it can calculate the elapsed time.
Why did we bother with the latches in TestHarness instead of just starting the threads immediately after they are created?
Presumably, we wanted to measure how long it takes to run a task n times concurrently. If we simply created and
started the threads, the threads started earlier would have a "head start" on the later threads, and the degree of
contention would vary over time as the number of active threads increased or decreased. Using a starting gate allows
the master thread to release all the worker threads at once, and the ending gate allows the master thread to wait for the
last thread to finish rather than waiting sequentially for each thread to finish.
1) The main thread start many threads, and let all of them await the startGate
2) The main thread countdown the startGate---release them all
3) The main thread await the endGate
4) Every thread ends, the thread will countdown the endGate
5) When all the threads finished, the main thread will be released to the next
code line—which calculate the long end, calculate the total execution time.
public class TestHarness {
public long timeTasks(int nThreads, final Runnable task)
throws InterruptedException {
final CountDownLatch startGate = new CountDownLatch(1);
final CountDownLatch endGate = new CountDownLatch(nThreads);
for (int i = 0; i < nThreads; i++) {
Thread t = new Thread() {
public void run() {
try {
startGate.await();//await() means current thread holds on
try {
task.run();
} finally {
//if countdown() reaches 0, release all threads waiting on this gate
endGate.countDown();
}
} catch (InterruptedException ignored) { }
}
};
t.start();
}
long start = System.nanoTime();
startGate.countDown();
endGate.await();
long end = System.nanoTime();
return end-start;
}
}
发表评论
-
javadoc for Cyclic Barrier
2009-04-24 12:48 903java.util.concurrent.CyclicBarr ... -
Delayed interface and Delay Queue
2009-04-22 17:42 1052/** * A standard implementati ... -
Count Down Latch example code
2009-04-22 10:38 1154Key point : 1) 1 task is co ... -
3 ways to break dead lock
2009-04-21 17:30 7621) supply special resources. ... -
Blocking Queue Usage
2009-04-20 11:21 8323 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 8491) wait(), notify() 方法被调用的时候,只要 ... -
Java Thread programming basical knowledge
2009-02-26 22:40 1088yield() : Give a hint to the th ... -
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 ...
相关推荐
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用来确保数据一致性、防止数据冲突的关键组件...
### CMOS Latchup详解 #### 一、引言 《关于CMOS Latchup的书》是由Steven H. Voldman所著的一本专业书籍,该书详细介绍了CMOS技术中的Latchup现象及其相关解决方案。Latchup是集成电路设计与制造过程中一个非常...
### FPGA中Latch简介 #### 一、什么是Latch? 在FPGA设计中,Latch(锁存器)是一种在异步时序电路系统中使用的存储单元,它对输入信号的电平敏感,用于存储信息。通常情况下,一个锁存器能够存储1比特的信息。...
Oracle通过一个隐含参数`_kghdsidx_count`来控制子共享池的数量。增加子共享池的数目可以提高并发性能,但同时也需要相应的内存资源。每个子共享池都有其独立的LRU(Least Recently Used)列表和Shared Pool Latch。...
在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)是集成电路设计与制造中两个至关重要的问题,它们直接关系到电路的可靠性和使用寿命。以下是对这两个概念及其相互关联的深入探讨。 ### 静电...
LATCH HA解决方案系统结构:两台主机A,B共享一个磁盘阵列,A为工作机,B为备份机。它们之间以一根心跳线来连接,这被称为“心跳检测”,主要通过一条 RS232检测链路来完成。LATCH HA也采用了网络ping检测来验证系统...
### Latch Contention详解 #### 摘要 本文提供了Oracle RDBMS如何利用锁(latches)保护共享内存(SGA)的概述、常见的锁竞争原因及其解决方案,并总结了Quest Software进行的一些研究,该研究表明调整(现在是未...