我想在 super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
中调用其他类,
setContentView(R.layout.activity_main);
中调用其他类,
解决方案 »
- unable to instantiate activity componentinfo in load dalvik.system. PathClassLoa
- 请教关于jar包中的控件显示问题
- android三级菜单
- 所以android开发人员走联盟这路估计不好走哦
- 关于源码目录的小白问题
- Activity中动态显示后台service的数据
- 求助:请大家帮我想一下Android手机平台上增强现实(AR)的应用创意。。。
- PC端连接android,搜索设备现在还用adb.exe吗?
- android新浪微博客户端授权问题
- 我的电脑用快捷键alt + insert 调不出来方法是怎么回事?
- 使用git clone 时 出错
- android sqlite 模糊查询
类看了教程还是迷糊
public final class Factorial {/**
* Default thread count(CPU count * 4)
*/
static final int THREAD_COUNT;
static {
THREAD_COUNT = Runtime.getRuntime().availableProcessors() << 2;
}/**
* Never instantiate this class.
*/
private Factorial() {
}/**
* Calculates the factorial of n. A new thread pool will be initialized to
* perform the calculation task, and destroyed thereafter.
*
* @param n
* the value of n
* @return the factorial of the given n
* @throws Exception
* if exception occurs
*/
public static final BigInteger factorial(final int n) throws Exception {
ExecutorService threadPool = Executors.newFixedThreadPool(THREAD_COUNT);
try {
return factorial(n, threadPool, THREAD_COUNT);
} finally {
threadPool.shutdown();
}
}/**
* Calculates the factorial of n. A specified thread pool will be used to
* perform the calculation task, and will not be automatically destroyed.
*
* @param n
* the value of n
* @param threadPool
* the given thread pool to perform the calculation task
* @param threadCount
* the number of threads to perform the calculation task
* @return the factorial of the given n
* @throws Exception
* if exception occurs
*/
public static BigInteger factorial(final int n, ExecutorService threadPool,
final int threadCount) throws Exception {List<Callable<BigInteger>> tasks = new ArrayList<Callable<BigInteger>>(
threadCount);
for (int i = 1; i <= threadCount; i++) {
final int threadNo = i;
Callable<BigInteger> worker = new Callable<BigInteger>() {@Override
public BigInteger call() throws Exception {
BigInteger result = BigInteger.ONE;
for (int x = threadNo; x <= n; x += threadCount) {
result = BigInteger.valueOf(x).multiply(result);
}
return result;
}};
tasks.add(worker);
}BigInteger result = BigInteger.ONE;
List<Future<BigInteger>> futureList = threadPool.invokeAll(tasks);
for (Future<BigInteger> future : futureList) {
result = future.get().multiply(result);
}
return result;
}
}