I used Java extension for my online game, which is working on SmartFoxServer
In the extension, threads don't stop working. they are always alive even if I shutdown that.
Our thread dump log has contains too many following lines
"pool-109758-thread-2" Id=2700 RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:171)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at sun.security.ssl.InputRecord.readFully(InputRecord.java:465)
at sun.security.ssl.InputRecord.read(InputRecord.java:503)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:975)
at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:933)
here is the sample of our code
public class sunucu_islemleri extends BaseServerEventHandler
{
ScheduledExecutorService scheduler;
Runnable RunnerTest;
public sunucu_islemleri() {
scheduler = Executors.newScheduledThreadPool(1);
RunnerTest = new Runnable() {
@Override
public void run() {
try {
scheduler.shutdown();
/**
some code samples
**/
}
catch (Exception hata) {
scheduler.shutdown();
}
}
};
}
public void handleSomeEvent() {
this.scheduler.schedule(RunnerTest, 10L, TimeUnit.SECONDS);
}
}
You want to use shutdownNow()
From the Javadocs:
shutdown() Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted.
shutdownNow() Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution.