Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-02-2008, 07:32 PM
Member
 
Join Date: Oct 2008
Posts: 3
John6715 is on a distinguished road
Killing an Ill-behaved Thread
I am working on a problem wherein my code is calling to a hardware device driver (written in Java and native code) and the thread is freezing. This in turn causes my application to freeze solid, requiring us to kill the JVM and restart it. To make a long story short, this is a support nightmare and one we would rather work around if possible.

The flow looks something like this:

1. Application controller thread receives a request to perform an action: this involves hardware interaction.

2. Our hardware framework spawns a thread to service the request.

3. The thread calls into a proprietary, closed-source driver for which we have no source code and cannot make any changes.

4. Said driver can, under specific circumstances, reach a point where it freezes. This causes our thread to freeze, which in turn will cascade up and cause the application to freeze. This is not technically deadlock but has similar characteristics. Removing this deadlock is what I am trying to do, but changing an application framework is not something to do lightly.

So far we have not been able to fix this. Part of the problem is design on our part, the system architecture is fairly robust but in some cases is very susceptible to threading problems. The second half of the problem is Java's lack of a "kill no matter what" mechanism for threads.

The driver itself traps all exceptions and all method calls that might stop it. It simply catches whatever we throw at it and continues waiting: for what we do not know.

Is there maybe a special Executor implementation that could do this? Maybe one that is written in native code, bypassing the (weak) Java kill mechanisms? I know the contract of Executor is that it provides additional thread management capabilities, is there any implementation that can do this?

While we have a support ticket open with the hardware vendor, this is not the first time this issue has come up. If I can find a way to kill such a thread then I will change our framework to handle this more gracefully. Neither myself nor my team's resident hardware guru are aware of any way to do this.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-02-2008, 07:50 PM
Senior Member
 
Join Date: Jun 2008
Posts: 483
masijade is on a distinguished road
Would it be possible to split of this device interaction into a completely separate process and communicate with it using jms or something to that effect. That way, the "main" program can kill and restart it itself whenever it gets into this "freeze" mode, without having to stop and restart the application.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 10-02-2008, 07:51 PM
Senior Member
 
Join Date: Jun 2008
Posts: 483
masijade is on a distinguished road
Also, if you have "robust" system, then hopefully, you have some software (probably a cluster software) that monitors the state of the application. That software could be the one that monitors the "device" part and restarts it when necessary, thereby removing that responsibilty from the application.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 10-02-2008, 10:58 PM
Member
 
Join Date: Oct 2008
Posts: 3
John6715 is on a distinguished road
We cannot use multiple processes to handle thread communication. That would make this easier.

The application itself is fairly robust and we did implement a fix that prevented the lockup, but has other side effects. Ideally we could kill the thread and try again, but so far that is not possible.

That is why I was hoping for an Executor that could dip down to the native level and kill the thread even if it does not want to die.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 10-02-2008, 11:51 PM
Senior Member
 
Join Date: Jun 2008
Posts: 483
masijade is on a distinguished road
Like I said, not "thread" communication. Use JMS (Java Messaging Service, I believe) or something similar. In other words the one process sends a request to the other and waits on a response.

And no, there is no safe way to "kill" a thread. And the "unsafe" way (with stop) is not likely to help you, especially if you're already having sync issues.

Edit: And, besides, I don't think killing the thread would help you in the first, as the process itself is probably what has all the locks, etc, on the device and those probably wouldn't go away simply by killing the thread that was actually performing the interaction, and so the problem would likely still exist after killing and restarting the thread.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 10-03-2008, 01:01 AM
Member
 
Join Date: Oct 2008
Posts: 3
John6715 is on a distinguished road
This is one application: due to constraints with how our customers use it, we cannot have multiple processes running. We have to use threads or we open ourselves up to much larger problems.

At this point if I could kill the thread it is worth a try. It may not work, but that is why we have a QA lab: to test this and document what happens under what circumstances. Unfortunately we cannot even use Thread.stop() as the inherent problem is the thread does not behave in the first place. Hopefully the hardware vendor can fix their Java driver, but that will take time, and like most vendors, they write perfect code and the problem is in the host application.

So I am back to my first question: is there some other way to kill this thread, even if I need to change how I manage its creation and use? E.g. using a different ThreadGroup or Executor? Even if I need native code to do it, there has to be a way. Maybe a third-party library that allows greater control?
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 10-03-2008, 10:35 AM
Senior Member
 
Join Date: Jun 2008
Posts: 483
masijade is on a distinguished road
It's not about control. It's about the fact that registers will be left open on any object it was using and will lead to other threads having incomplete objects and, therefore undefined behaviour.

But hey, if you are simply going to dismiss any suggestion anyone makes and stay doggedly by the belief that your idea is the only one that can work. More power to you.

BTW, there are plenty of applications that use more than process, and I can guarantee you have a few of them running on your home PC whenever you turn it on, so, no, I don't buy that argument. It is simply not what you want to do, or just because it is not your idea, so you dismiss it out of hand. Well, good luck then. If you want some third party thread library, Google for one.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Thread killing denis Threads and Synchronization 13 09-25-2008 11:28 PM
passing a value from parent thread to child thread sachinj13 Threads and Synchronization 7 09-07-2008 11:06 PM
data from the main/GUI thread to another runnin thread... cornercuttin Threads and Synchronization 2 04-24-2008 12:30 AM
If JNI thread call the java object in another thread, it will crash. skaterxu Advanced Java 0 01-28-2008 09:02 AM
Creating a Thread (extending Java Thread Class) JavaForums Java Blogs 0 12-19-2007 11:31 AM


All times are GMT +3. The time now is 09:30 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org