I ran into an issue where interrupting a thread before doing a queue poll doesn't cause the poll operation to return immediately or throw an interrupted exception. From the best I can tell the interrupt is properly detected in AbstractInvocationFuture line 156 - 160 but the park() call is in an infinite for loop so after detecting the interrupt the loop just goes back to being parked. I didn't try interrupting from a separate thread but I suspect the same issue exists. This makes it tough to interrupt a queue polling thread.
Am I missing something or is this a bug introduced with the move to park/unpark with Hazelcast 3.7?
Thanks.
public static void main(String[] args) {
Config config = new Config();
config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);
try {
// Interrupt the thread.
Thread.currentThread().interrupt();
// Verify that park detects existing interrupt.
System.out.println("Time before lock: " + System.currentTimeMillis());
LockSupport.parkNanos(TimeUnit.MINUTES.toNanos(5));
System.out.println("Time after lock: " + System.currentTimeMillis());
// Interrupt the thread again.
Thread.currentThread().interrupt();
// Verify that queue poll detects existing interrupt.
System.out.println("Time before poll: " + System.currentTimeMillis());
hz.getQueue("test").poll(1, TimeUnit.MINUTES);
System.out.println("Time after poll: " + System.currentTimeMillis());
}
catch (Exception ex) {
ex.printStackTrace();
}
finally {
hz.shutdown();
}
}
Aug 02, 2016 10:41:36 AM com.hazelcast.core.LifecycleService
INFO: [10.52.1.26]:5701 [dev] [3.7-SNAPSHOT] [10.52.1.26]:5701 is STARTED
Time before lock: 1470148896606
Time after lock: 1470148896606
Time before poll: 1470148896606
Aug 02, 2016 10:41:36 AM com.hazelcast.internal.partition.impl.PartitionStateManager
INFO: [10.52.1.26]:5701 [dev] [3.7-SNAPSHOT] Initializing cluster partition table arrangement...
Time after poll: 1470148957368
Aug 02, 2016 10:42:37 AM com.hazelcast.core.LifecycleService
INFO: [10.52.1.26]:5701 [dev] [3.7-SNAPSHOT] [10.52.1.26]:5701 is SHUTTING_DOWN