- 浏览: 126967 次
- 性别:
- 来自: 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
The important thing need to look at is, use multiple threads(Callable), let them run together, and retrieve results from them.
package com.oreilly.tiger.ch10;
import java.math.BigInteger;
import java.security.SecureRandom;
import java.util.Random;
import java.util.concurrent.Callable;
import static java.lang.System.out;
public class RandomPrimeSearch implements Callable {
private static final Random prng = new SecureRandom();
private int bitSize;
public RandomPrimeSearch(int bitSize) {
this.bitSize = bitSize;
}
public BigInteger call() {
return BigInteger.probablePrime(bitSize, prng);
}
public static void main(String args[])
{
//use ExecutorService to organize many Callables.
ExecutorService service = Executors.newFixedThreadPool(5);
Future prime1 = service.submit(new RandomPrimeSearch(512));
Future prime2 = service.submit(new RandomPrimeSearch(512));
Future prime3 = service.submit(new RandomPrimeSearch(512));
try {
BigInteger bigger = (prime1.get().multiply(prime2.get())).multiply(prime3.get());
out.println(bigger);
} catch (InterruptedException e) {
e.printStackTrace(out);
} catch (ExecutionException e) {
e.printStackTrace(out);
}
}
}
==========================================================
Uage of FutureTask
If you have only one Callable, you can just
1) use FutureTask, wrap your Callables.
2) use Thread, wrap your FutureTask, start the thread
3) retrieve results from FutureTask.
FutureTask<BigInteger> task = new FutureTask<BigInteger>(new RandomPrimeSearch(512));
new Thread(task).start( );
BigInteger result = task.get( );
发表评论
-
javadoc for Cyclic Barrier
2009-04-24 12:48 905java.util.concurrent.CyclicBarr ... -
Delayed interface and Delay Queue
2009-04-22 17:42 1054/** * A standard implementati ... -
Count Down Latch example code
2009-04-22 10:38 1155Key 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 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 725Timer typical usage new Tim ... -
wait, notify及线程通讯机制
2009-02-26 22:42 8511) wait(), notify() 方法被调用的时候,只要 ... -
Java Thread programming basical knowledge
2009-02-26 22:40 1090yield() : 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 1107Executor can return Executor, E ... -
Executor usage
2008-07-22 11:04 904Executor is used to arrange thr ...
相关推荐
Rcpp attributes provide a high-level syntax for declaring C++ functions as callable from R and automatically generating the code required to invoke them. Attributes are intended to facilitate both ...
The usage is simple, you just need to create a class that implements LifeCycleAware and modify your Activity/Fragment adding a field annotated with @BindLifeCycle and invoking LifeCycleBinder.bind...
4. **Deprecated Functions and Keywords:** Several functions like `cmp()`, `reduce()`, `apply()`, `callable()`, and `reload()` were removed or replaced, and new keywords like `as`, `with`, and `...
Usage usage = parameter -> parameter; ``` 这比使用匿名内部类更加简洁和易于阅读。 5. **避免重写Functional Interface作为参数的方法**: 当一个方法接受Functional Interface作为参数时,应避免在实现中...
Performance and resource usage PEP 397: Python Launcher for Windows PEP 3151: Reworking the OS and IO exception hierarchy PEP 380: Syntax for Delegating to a Subgenerator PEP 409: Suppressing ...
Usage Conventions 74 Summary 81 Chapter 3: Objects and Types 83 Classes and Structs 84 Class Members 85 Data Members 85 Function Members 85 xi Contents readonly Fields 99 Structs 101 Structs Are Value...
[!... ... The Google API Client Library enables you to work with Google APIs such as Google+, Drive, or YouTube on your server. These client libraries are officially supported by Google....
if len(args) == 1 and len(kwargs) == 0 and callable(args[0]): # Actual decorated function return f(args[0]) else: # Decorator arguments return lambda realf: f(realf, *args, **kwargs) return new...
Simplifying Usage of Strings' translate Method Recipe 1.10. Filtering a String for a Set of Characters Recipe 1.11. Checking Whether a String Is Text or Binary Recipe 1.12. Controlling Case ...
Detours preserves the un-instrumented target function (callable through a trampoline) as a subroutine for use by the instrumentation. Our trampoline design enables a large class of innovative ...
Callable Objects....................................2 Calling Functions...................................3 Functions Control..................................3 Decorators................................