1

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);
    }
}
Muhammet Demir
  • 1,995
  • 5
  • 21
  • 42
  • 1) did you run your sample at least once - to see if the pool is shutting down? 2) Why do you assume that it is your pool shown in the dump? – Eugene Apr 01 '21 at 15:52
  • A quick test on my end shows that an `Executor` *does* shutdown and not hold up a JVM from exiting if the executor is `shutdown()`. So "it works for me." You'll have to offer some better code and a better rational why you think it's the executor at fault, as Eugene is saying in his comment. – markspace Apr 01 '21 at 18:49

2 Answers2

1

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.

Ryan
  • 1,762
  • 6
  • 11
0

when RunnerTest runs -> scheduler.shutdown() when your event handles -> scheduler.schedule(RunnerTest)

so an event trigger that -> the scheduler to schedule a runnable to stop the scheduler that seems to be "the scheduler" is open for suicide! I do not want to judge the scheduler but it is not common behavior.

Please consider setting a flag that makes RunnerTest business stop and try to shut down the scheduler outside of the thread.

Onurus
  • 54
  • 1
  • 4