I am searching a way to catch an NullPointerException
in a Runnable
class.
I have this method called by 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);
}
}
and I have this code in another class which call a class 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()) { }
As you can see, the NullPointerException
is really important to add an item so I need the values of contextIndex
and targetIndex