Java ScheduledExecutorService does not print stack trace on exceptions

51 views
Skip to first unread message

Srikanth Vavilapalli

unread,
May 12, 2015, 9:53:11 PM5/12/15
to onos...@onosproject.org
Hi

Apparently, in Java, when the threads/tasks, spawned using any ScheduledExecutorService APIs (schedule(), scheduleAtFixedRate()...etc), throw any exception, the stack trace does not appear on the console or log unless an explicit try/catch block in the run() method catches the exception and logs it.

We have realized this while debugging the segment routing application where our executor threads silently getting vanished without any exceptions in the ONOS logs. 

As per javadoc of ScheduledExecutorService, "If any execution of the task encounters an exception, subsequent executions are suppressed."

So if you are using this service in any of your module, add an explicit try/catch block in the run() method to print the stack trace in the ONOS logs..

Regards
Srikanth 

Yuta Higuchi

unread,
May 13, 2015, 12:02:34 AM5/13/15
to Srikanth Vavilapalli, onos...@onosproject.org
You might want to consider using the version of newScheduledThreadPool(..) which you can specify a ThreadFactory when creating the ScheduledExecutor.
And also use org.onlab.util.Tools.namedThreads(String) etc. to create the ThreadFactory.

It should, in theory, log something if Exception leaked out from the Runnable, etc.
in addition to giving the thread a descriptive name.

Your suggestion to catch exception is still valid, especially when periodic task is being executed though.
I believe when Exception leaks out, next periodic task will not be triggered.


--
You received this message because you are subscribed to the Google Groups "ONOS Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to onos-dev+u...@onosproject.org.
To post to this group, send email to onos...@onosproject.org.
Visit this group at http://groups.google.com/a/onosproject.org/group/onos-dev/.
To view this discussion on the web visit https://groups.google.com/a/onosproject.org/d/msgid/onos-dev/CAC1GD-f0e-ybVcoSuh04-YJm36%3DPG6kM7u_g8SQhg%2B8Q5cwoaQ%40mail.gmail.com.

Reply all
Reply to author
Forward
0 new messages