Results 1 to 4 of 4
Thread: problem with a guarded block !
- 12-16-2008, 04:28 PM #1
Member
- Join Date
- Apr 2008
- Posts
- 42
- Rep Power
- 0
problem with a guarded block !
i've created a button in netbeans and it calls a method that involves a file IO, o when i want to modify the code inside buttonMouseClicked i can't because it says its guarded !!
private void jButton41MouseClicked(java.awt.event.MouseEvent evt) {
getDefinition(); <==== CAN'T DELETE THIS!
}
how can i solve this please ?
thanks in advance :D
- 12-20-2008, 02:59 PM #2
Member
- Join Date
- Apr 2008
- Posts
- 42
- Rep Power
- 0
Guys please ive been waiting for ur reply since tuesday :'( .. I really need help in this .
-
This is not truly a Java question but instead is a NetBeans-related question. If you continue without a decent reply, you might want to look for a NetBeans forum. Myself, I avoid using NetBeans generated code but instead code all my Swing apps by hand. Best of luck.
- 01-03-2011, 12:10 AM #4
Member
- Join Date
- Jun 2009
- Posts
- 8
- Rep Power
- 0
guarded block issue -- please help
I have attempted to implement an example of guarded blocks I've obtained at Guarded Blocks (The Java™ Tutorials > Essential Classes > Concurrency) The following code was generated:
Main.java:
package testthreads3;
public class Main extends Thread
{
public static void main(String[] args)
{
Boolean joy = false;
Thread1 thread1 = new Thread1(joy);
Thread2 thread2 = new Thread2(joy);
thread1.start();
thread2.start();
}
}
Thread1.java:
package testthreads3;
public class Thread1 extends Thread
{
private Boolean joy;
public Thread1(Boolean joy)
{
this.joy = joy;
}
public synchronized void guardedJoy()
{
while(!joy)
{
try
{
wait();
} catch (InterruptedException e) {e.printStackTrace();}
}
System.out.println("Joy and efficiency have been achieved!");
}
@Override
public void run()
{
guardedJoy();
}
}
Thread2.java:
package testthreads3;
public class Thread2 extends Thread
{
private Boolean joy;
public Thread2(Boolean joy)
{
this.joy = joy;
}
public synchronized void notifyJoy()
{
joy = true;
notifyAll();
}
@Override
public void run()
{
notifyJoy();
}
}
From my understanding, Thread1 is in waiting state and has joy set to false. Thread2 sets joy to true and sets Thread1 back to ready state with notifyall() method. On the contrary, the following occur unexpectedly:
1) Both threads have two different instances of joy of different values. I expect the values to be the same since they both refer to the same variable joy defined in main.
2) Thread1 is never notified. InterruptedException is never thrown and the program keeps running.
Please help, greatly appreciate
Similar Threads
-
need block letters??
By dc2acgsr99 in forum New To JavaReplies: 16Last Post: 01-29-2008, 08:31 AM -
Programming block
By Java Tip in forum Java TipReplies: 0Last Post: 12-25-2007, 11:20 AM -
try...catch block
By javaplus in forum New To JavaReplies: 3Last Post: 11-06-2007, 07:53 PM -
Return to try block
By Freddie in forum New To JavaReplies: 2Last Post: 05-11-2007, 08:58 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks