• Registered (unregistered)

    In case of an exception, traffic is started but only stdout will be saturated

  • (nodebb)

    I've never even heard of the Thread.destroy() method in Java before. Apparently the Javadoc says that it was never implemented! So that line of code is certainly useless, and if Thread.destroy() had been implemented, there would be an extreme risk of deadlock here—if the thread had held any locks when it was being destroyed, those locks wouldn't ever get released.

  • (nodebb)

    That Thread.destroy() call is worse than useless. According to the Javadoc, it always throws a NoSuchMethodError! Luckily, NoSuchMethodError extends Error rather than Exception, so that catch block doesn't catch it, so there's no infinite loop. It still means that a second thread will never be created though.

  • (nodebb)

    Wait. You can throw something that isn't catchable in Java???

  • (nodebb) in reply to colejohnson66

    I assume you can catch it, you just have to be explicit with catch (Error e).

    Python also has some error types that aren't subtypes of Exception.

  • (nodebb)

    Yeah, catch (Error e) would work for catching Errors but not Exceptions. You can also do catch (Throwable e) for catching both Errors and Exceptions. Generally, things that you shouldn't normally be trying to catch extend Error so that people don't accidentally catch them and ignore them.

  • Rob (unregistered) in reply to adamantoise

    Thread.destroy() has been deprecated for removal since at least Java 8, and was actually removed in Java 11. Here's a link to its documentation from Java 10: https://docs.oracle.com/javase/10/docs/api/java/lang/Thread.html#destroy()

  • Rob (unregistered) in reply to colejohnson66
    Comment held for moderation.
  • (nodebb) in reply to Balor64

    Oh, is this a workaround for the whole checked exception design flaw?

  • (nodebb) in reply to MaxiTB

    No, the workaround for that is RuntimeException, which is a subclass of Exception. RuntimeException and anything that extends it will not be checked at compile time, so you don't need to declare them in your method signatures (though you can anyway, if you want to).

Leave a comment on “Pulling at the Start of a Thread”

Log In or post as a guest

Replying to comment #679487:

« Return to Article