-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
8, 11, 17, 18, 19
-
generic
-
generic
ADDITIONAL SYSTEM INFORMATION :
JDK11
A DESCRIPTION OF THE PROBLEM :
When the thread pool uses futuretask, if the rejection policy is set to discardpolicy and discardoldestpolicy and the parameterless get method is called on the future object of the rejected task, the calling thread will always be blocked.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a new thread pool. Set the number of core threads, the maximum number of threads and the size of the work queue to be smaller. Set the rejection policy to ThreadPoolExecutor DiscardPolicy (), then call submit to add the task until it triggers the rejection policy, then calls the FutureTask#get method, and finds that it will remain blocked.
ACTUAL -
Always blocked
---------- BEGIN SOURCE ----------
public class FutureTest {
private final static ThreadPoolExecutor executorService = new ThreadPoolExecutor(1, 1, 1L, TimeUnit.MINUTES,
new ArrayBlockingQueue<Runnable>(1),new ThreadPoolExecutor.DiscardPolicy());
public static void main(String[] args) throws Exception {
Future futureOne = executorService.submit(new Runnable() {
@Override
public void run() {
System.out.println("start runable one");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
Future futureTwo = executorService.submit(new Runnable() {
@Override
public void run() {
System.out.println("start runable two");
}
});
Future futureThree=null;
try {
futureThree = executorService.submit(new Runnable() {
@Override
public void run() {
System.out.println("start runable three");
}
});
} catch (Exception e) {
System.out.println(e.getLocalizedMessage());
}
System.out.println("task one " + futureOne.get());
System.out.println("task two " + futureTwo.get());
System.out.println("task three " + (futureThree==null?null:futureThree.get()));
executorService.shutdown();
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
ThreadPoolExecutor. The discardpolicy rejection policy should set the status of futuretask to cancel or other status. Anyway, it only needs to be greater than the completing status
JDK11
A DESCRIPTION OF THE PROBLEM :
When the thread pool uses futuretask, if the rejection policy is set to discardpolicy and discardoldestpolicy and the parameterless get method is called on the future object of the rejected task, the calling thread will always be blocked.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a new thread pool. Set the number of core threads, the maximum number of threads and the size of the work queue to be smaller. Set the rejection policy to ThreadPoolExecutor DiscardPolicy (), then call submit to add the task until it triggers the rejection policy, then calls the FutureTask#get method, and finds that it will remain blocked.
ACTUAL -
Always blocked
---------- BEGIN SOURCE ----------
public class FutureTest {
private final static ThreadPoolExecutor executorService = new ThreadPoolExecutor(1, 1, 1L, TimeUnit.MINUTES,
new ArrayBlockingQueue<Runnable>(1),new ThreadPoolExecutor.DiscardPolicy());
public static void main(String[] args) throws Exception {
Future futureOne = executorService.submit(new Runnable() {
@Override
public void run() {
System.out.println("start runable one");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
Future futureTwo = executorService.submit(new Runnable() {
@Override
public void run() {
System.out.println("start runable two");
}
});
Future futureThree=null;
try {
futureThree = executorService.submit(new Runnable() {
@Override
public void run() {
System.out.println("start runable three");
}
});
} catch (Exception e) {
System.out.println(e.getLocalizedMessage());
}
System.out.println("task one " + futureOne.get());
System.out.println("task two " + futureTwo.get());
System.out.println("task three " + (futureThree==null?null:futureThree.get()));
executorService.shutdown();
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
ThreadPoolExecutor. The discardpolicy rejection policy should set the status of futuretask to cancel or other status. Anyway, it only needs to be greater than the completing status