The number of threads (id) increases when the thread completes, and a new thread is created. Is Java 7 just an increasing number or am I doing something wrong?
I am building an application using Java 7, which creates a new thread on connection and then serves the connection. When the service receives a close message, it exits the loop and allows code to complete in the stream. Thus, the life of the stream supposedly ends, as I understand it (just like any object of the object). Java 7 does not use Thread.stop () or Thread.destroy () or any such thing. (Since, as I think, 5).
I have an interface with the buttons "Open connection", "Close connection" and "Send message" and the corresponding println instructions in the stream so that I can see what is happening. One of the variables I'm printing is Thread.currentThread (). When I open the first connection, currentThread () represents Thread [Thread-0,5, main]. I close the connection and exit the loop, indicating that Thread [Thread-0.5, main] is ending.
OK, so now it goes back to the square, right? There are no threads.
I reconnect and join Thread [Thread-1,5, main]. See that? "Thread-1" instead of "Thread-0". Every time I do this, the number increases by 1.
(A side question if itβs not so difficult. What does β5, the main thingβ mean?)
Comment re: thread stop: Why are Thread.stop, Thread.suspend and Thread.resume deprecated? .
source share