JNA callback method wont be called until futureTask.get() timeout

83 Views Asked by At

If I run like this, the callback block will not run so future.get() will block forever:

FutureTask<Long> futureTask = new FutureTask<>(System::currentTimeMillis);

boolean login = CameraSDk.login(ip, port, userName, password, 
       (lLoginID, pBuf, RevLen, EncodeType, CmdSerial, dwUser) -> {
    //do something
    futureTask.run();
});

try {
    Long timestamp = futureTask.get();
    System.out.println("timestamp = " + timestamp);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
    e.printStackTrace();
}

But if I use this:

Long timestamp = futureTask.get(1, TimeUnit.SECONDS);

The callback block will be called when futuretask.get() times out.

I don't know what happened, is this a dead lock or something else?

0

There are 0 best solutions below