-1

I have the problem that there seems to be some threads that aren't terminated right. When I pause one of this threads in debug mode I get this list:

Thread [<14> pool-2-thread-1] (Suspended)   
    <VM does not provide monitor information>   
    Object.wait(long, int) line: not available [native method]  
    Thread.parkFor(long) line: 1205 
    Unsafe.park(boolean, long) line: 325    
    LockSupport.park(Object) line: 159  
    AbstractQueuedSynchronizer$ConditionObject.await() line: 2019   
    LinkedBlockingQueue.take() line: 413    
    ThreadPoolExecutor.getTask() line: 1013 
    ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker) line: 1073  
    ThreadPoolExecutor$Worker.run() line: 573   
    Thread.run() line: 841

before I paused it, it was "Running" instead of Suspended. How can I find out which thread that is?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Ginso
  • 459
  • 17
  • 33
  • 4
    Well, this list is of course much more helpful than, let's say... the actual code. – SME_Dev Nov 14 '14 at 09:15
  • i can't write my whole project here, i don't even know which thread this is... that's what i want to find out – Ginso Nov 14 '14 at 09:27
  • 1
    1. When creating a thread, you can name it by `setName()`. 2. You should investigate, under which conditions the thread's runnable implementation can return/terminate. If there is no such condition (or it's never met), then you've got the answer. – SME_Dev Nov 14 '14 at 09:29
  • What's the problem then? You may not have started that thread, the os could have, it seems like a thread in a pool used by an executor. What harm does it cause, why are you concerned about it? – JHH Apr 02 '21 at 22:12

1 Answers1

0

This Thread seems to be a "spare" thread kept in a thread pool, waiting for something to do. It is not executing your code.

This is completely normal.

Thomas Stets
  • 3,015
  • 4
  • 17
  • 29
  • the problem is, that when i back to my start activity and then do the same steps again, it starts a new thread for this. There fore if i do that more often, i get more and more threads. That's not very nice since i don't need anything from the old threads. How can i cancel these? I found out that there is a point where this thread is called using Thread.currentThread(). what can i do with this thread to terminate it? – Ginso Nov 14 '14 at 13:58
  • How many Threads do you get? Check the section "Core and Maximum Pool Sizes" in this link whether it fits your problem: https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor.html It basically says, that up to a configured limit it does what you describe: start new Threads for a new task. However, once the core pool size is reached no new Threads should be created if there are idle ones. – Thomas Stets Nov 14 '14 at 14:46