Java Executors: how can I stop submitted tasks?

后端 未结 5 934
抹茶落季
抹茶落季 2020-12-01 12:48

I have submitted a task using executors and I need it to stop after some time (e.g. 5 minutes). I have tried doing like this:

   for (Future fut : e         


        
5条回答
  •  甜味超标
    2020-12-01 13:32

    The most common case for ConcurrentModificationException is when the vector is being modified at the same time as it is being iterated. Often this will be done in a single thread. You need to hold a lock on the Vector for the whole iteration (and careful not to deadlock).

提交回复
热议问题