我正在寻找一种方法来捕捉NullPointerException
课程中的Runnable
。
我有run
调用此方法:
private void cooccurrence(int contextIndex, int targetIndex) {
try {
Double old_value = X.get(contextIndex, targetIndex);
X.set(contextIndex, targetIndex, old_value + 1);
}catch (NullPointerException e) {
X.growData(X.nz_length + 1);
X.addItem(contextIndex, targetIndex, 1);
}
}
我将此代码放在另一个调用类ThreadForX implements Runnable
的类中:
final BlockingQueue<JSONObject> queue = new
ArrayBlockingQueue<>(5000000);
int json_object_in_queue = 0;
ExecutorService pool = Executors.newFixedThreadPool(2);
DMatrixSparseTriplet X = new DMatrixSparseTriplet(200000,200000,0);
JSONObject inQueue_jsonObject;
while ((inQueue_jsonObject = queue.poll()) != null) {
Runnable readTweet = new ThreadForX(contextLenght, inQueue_jsonObject, X, final_vocabulary);
pool.execute(readTweet);
}
pool.shutdown();
while (!pool.isTerminated()) { }
正如您所看到的,NullPointerException
对于添加项目非常重要,因此我需要contextIndex
和targetIndex
的值