I am writing a multithreaded program in java. I have written something like this
exec.execute(p) // where p is a runnable task working on an array
print array
exec.shutdown
The problem I am facing is that the array gets printed giving the correct output but then the rejected Execution Exception comes
I don’t understand why when the threads have processed and given the correct output why is the error coming…
I think you are shutting down your executor too early. This is an example how I think you should be working.
Also note that working on the same array at the same time could cause inconsistency – you must be really sure that you are not doing work on the array that depends on the array.