Do I always have to return something using Worker Thread in Swing? What if I don’t have any return value? I just want to use the worker thread to run an infinite for loop… so what to return? and even if I write a dummy return statement after the infinite for loop, say for e.g return 0; then also it will probably say “code not reachable”.
Share
I suspect you haven’t tried it. The code you’ve suggested in the comment should work fine:
A tight loop like this seems like a bad idea to me, and the
repaint()code will need to be made appropriately thread-safe, but it should compile…Personally I prefer to use
while (true)for “forever” loops, butfor (;;)should work too.