Basically I have the following:
main program:
1)made up LinkedList
2)calls thread
thread:
1) accessing first on linked list
2) using the variable first on the list
3) removing the first on the list
4) considering next on the list
Basically I am trying to access a linked list I created from a separate thread. I can access this linked list inside the same thread but once I try from a different thread it gives me the following error:
Exception in thread "Thread-3" java.lang.NullPointerException
at Heater$CheckList.run(Heater.java:633)
I have declared the list globally. Is there something I have missed out? A basic layout of what I need to do in Java language would be great.
Problems with linked lists in Java?
Without looking at your code (and I really don't want to)... threads are such a deadlock (or race) condition that java has gone over to a single-thread mechanism, just for sanity sake, so there is a hope for debugging.
In your problem, I THINK you have deadlock requesting a spawn before a new thread can start. In the old days they used to enumerate all the threads, see if any threads were running and threadY.join(); Doing this thread on linked list is proceedural. Do one step out of order, you get lock.
The only time I have used linked lists was in a classroom environment. If I program for things money and it requires threads, I will ONLY do such software in Swing, using the single-mechanism of:
public static main() {
SwingUtilities.
invokeLater(new Runnable() {
public void run() {
// code here
}
});
}
if I want to join that above thread in progress, I spawn with:
if(SwingUtilities.
isDispatchThread() ) {
// code.run();
} else {
SwingUtilities.
invokeLater( code );
}
////////
So, declaring your List "globally" has nothing to do with this deadlock. Exception thrown is Heater.innerClass.run %26lt;-- thread
Reply:Hmmm....do you have the latest version of Java installed?
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment