Swing timer persistence after main method finishes

前端 未结 2 793
误落风尘
误落风尘 2020-12-20 21:53

I am trying to create a program to perform a simple task and produce an output every x seconds. I also want the program to run until I decide to manually close

相关标签:
2条回答
  • 2020-12-20 22:24

    Use java.util.Timer instead. The associated thread will not run as a daemon.

    0 讨论(0)
  • 2020-12-20 22:50

    A Swing Timer will stay alive as long as the EDT is alive, usually this is done by having a Swing GUI present and visible (this creates a non-daemon thread that persists until the GUI exits). If you don't need a Swing GUI, then don't use a Swing Timer. Perhaps instead use a java.util.Timer, and don't exit the main method til you give the word (however you plan to do that).

    0 讨论(0)
提交回复
热议问题