Giter Club home page Giter Club logo

Comments (5)

calimero-project avatar calimero-project commented on June 11, 2024

Thank you for your report!
Why would it prevent breaking the loop? Having entered wait is not a prerequisite for detecting the interrupt.

Do you maybe have a concrete example for when that happened?

from calimero-core.

Maw-Jung avatar Maw-Jung commented on June 11, 2024

From my understandings entering wait is a prerequisite to detect an interrupt in the loop trough an InterruptedException, since it's a method designed to throw one if interrupt is invoked. Sure, entering wait is in general not a prerequisite to detect an interrupt, but in this loop of the calimero project it is, because it will only stop on catching an InterruptedException. I got a concrete case of this problem in a large scale application, maybe i can find the time to give a reproducing example. Thanks for the quick reply, please let me know if further information to my explanation are needed.

from calimero-core.

calimero-project avatar calimero-project commented on June 11, 2024

As I see it, your problem can be described by the following sequence (producing an execution equivalent to the event notifier):

Thread.currentThread().interrupt();
System.out.println("thread interrupted = " + Thread.currentThread().isInterrupted());
final Object lock = new Object();
try {
	while (true) synchronized (lock) { lock.wait(); }
}
catch (final InterruptedException e) {
	System.out.println(e);
}
System.out.println("thread exit");

Which will exit the thread, and is in accordance with the expected behavior of wait.

So yes, please provide a stack trace, snapshot, or example where this fails, so I can see the root cause.

from calimero-core.

Maw-Jung avatar Maw-Jung commented on June 11, 2024

You were right on the behavior of the interrupt flag, my bad. I had the time to dig deeper and found the root cause of the issue i saw. It's connected to the openhab issue openhab/openhab1-addons#1068. We use a similar way of connecting to calimero: When the connection is lost, calimero fires a CloseEvent. Any attached NetworkLinkListener will be fired, in the current EventNotifier Thread. If the linkClosed method of such handles the disconnection, there is no problem. In this case the connection was also handled through that method call, which will keep the old EventNotifier Thread open and drive the application into the undefined state mentioned above. For reference, the issue can be solved by spawning the reconnect task in a new Thread, through a scheduled TimerTask for example. Thanks for your help, i'll close this issue since it was a wrong use of the library.

Greetings,
Marcel

from calimero-core.

calimero-project avatar calimero-project commented on June 11, 2024

Good to know it worked out, thanks for the feedback. (The problem you describe is basically a form of thread hijacking, which should in general be avoided.)

from calimero-core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.