- 浏览: 121427 次
- 性别:
- 来自: 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 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 1090Key point : 1) 1 task is co ... -
3 ways to break dead lock
2009-04-21 17:30 7041) supply special resources. ... -
Blocking Queue Usage
2009-04-20 11:21 7963 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 862ExecutorService 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 8051) wait(), notify() 方法被调用的时候,只要 ... -
Java Thread programming basical knowledge
2009-02-26 22:40 927yield() : 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 ...
相关推荐
CPLEX Callable Library 2009 manual
callable用法
callable_traits, callable类型的现代 C 型特征和泛函 Boost.CallableTraits CallableTraits是一个C 11头库,用于检查。合成和分解可以调用类型。这里有最新的文档,这里是 。在CallableTraits中,被正式地检查过,...
JAVA中Callable的使用。下载后评论可返分
Callable,Future的使用方式,里面使用了三种使用方式分别是FutureTask,ExecutorService,ExecutorCompletionService
java并发包之Callable和Future java并发包之Callable和Future java并发包之Callable和Future java并发包之Callable和Future java并发包之Callable和Future java并发包之Callable和Future
主要介绍了Java使用Callable和Future创建线程操作,结合实例形式分析了java使用Callable接口和Future类创建线程的相关操作技巧与注意事项,需要的朋友可以参考下
自留demo,主要是Thread-Callable-Future的基本实现。 参考文章: 1、深入理解Callable https://blog.csdn.net/qq_19431333/article/details/77483763 2、彻底理解Java的Future模式: ...
一直以来感觉使用Mybatis查询存储过程很蹩脚,不知道有没有人和我感觉一样。写了一个拦截器,可以把储存过程的输出参数当做返回值来返回。其实也简单不了多少,只不过在设计Dao接口的时候能更统一吧。...
主要介绍了Django 错误:TypeError at / 'bool' object is not callable解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
通过合规策略对服务器进行监控,确保服务器的运行、帐号在服务器上的操作符合预设的规则。日志:收集、整理服务器的日志信息,提供给管理员查看,并作为异常判断、故障排查的依据。进程:监控服务器上的进程,并对...
大家都知道Runnable和Callable接口都可以作为其他线程执行的任务,但是Runnable接口的run方法没有返回值,而Callable接口的call方法有返回值,那么Callable接口是如何做到的呢?在此我给出一个Demo,看看通过...
Runnable是执行工作的独立任务,但是它不返回任何值,如果你希望任务在完成时能够返回一个值,那么可以实现Callable接口而不是Runnable接口。在Java SE5中引入的Callable是一种具有类型参数的泛型,它的类型参数表示...
主要介绍了Java中的Runnable,Callable,Future,FutureTask的比较的相关资料,需要的朋友可以参考下
Callable和Future详解: Callable和Runnable有几点不同: (1)Callable规定的方法是call(),而Runnable规定的方法是run(); (2)call()方法可抛出异常,而run()方法是不能抛出异常的。 (3)Runnable不会返回结果,...
NULL 博文链接:https://pengqb.iteye.com/blog/738210
Callable接口的基本用法 2.1 创建Callable任务 2.2 提交Callable任务 2.3 获取任务执行结果 Future接口的使用 3.1 获取任务执行状态 3.2 取消任务的执行 Callable与Runnable的对比 Callable的异常处理 Callable的...
61Callable Bond V3.xls
callable() 描述 callable() 函数用于检查一个对象是否是可调用的。如果返回 True,object 仍然可能调用失败;但如果返回 False,调用对象 object 绝对不会成功。 对于函数、方法、lambda 函式、 类以及实现了 `__...
2.细看2.1接口说明2.1.1泛型参数说明Interface Callable<V>V - the result type of method call2.1