thread error  
Author Message
Mandilas Antony





PostPosted: 2003-10-28 1:18:00 Top

java-programmer, thread error i face the following error..

i have a JTextPanel and a thread that checks every 1sec if there is data
in an imputstream and write them to the text panel.. i have also a
button with which i want to "pause" the thread...

i try to do it with the following way:

void jButtonPause_mouseReleased(MouseEvent e) {
if (thread_state == true) {
jTextArea.append("\n try to stop thread \n");
try {
synchronized (this) {
t.notify();
t.wait();
}
thread_state = false;
jButtonPause.setText("Resume");
}
catch (InterruptedException ex) {
jTextArea.append(ex.getMessage());
}
}
else {
synchronized (this) {
t.notify();
}
thread_state = true;
jButtonPause.setText("Pause");
}
}

the above is the code for the button. the thread t is actually created
in a function

public void threadReadData() {
if (t == null) {
t = new Thread("Read GPS Data") {
public void run() {
jTextArea.setText("");
.
.
.

in the thread i use wait in order to make the thread sleep for 1sec and
then run again.

And now the problem.. when i press the button i get a
java.lang.IllegalMonitorStateException:current thread not owner

how can i solve the above error??

Best regards
Mandilas Antonis

 
Mandilas Antony





PostPosted: 2003-10-28 1:27:00 Top

java-programmer >> thread error ok.. i managed to pause the thread but i changed the code to this

synchronized (t) {
t.notify();
t.wait();
}

but now the gui freazes too! :(

Mandilas Antony wrote:

> i face the following error..
>
> i have a JTextPanel and a thread that checks every 1sec if there is data
> in an imputstream and write them to the text panel.. i have also a
> button with which i want to "pause" the thread...
>
> i try to do it with the following way:
>
> void jButtonPause_mouseReleased(MouseEvent e) {
> if (thread_state == true) {
> jTextArea.append("\n try to stop thread \n");
> try {
> synchronized (this) {
> t.notify();
> t.wait();
> }
> thread_state = false;
> jButtonPause.setText("Resume");
> }
> catch (InterruptedException ex) {
> jTextArea.append(ex.getMessage());
> }
> }
> else {
> synchronized (this) {
> t.notify();
> }
> thread_state = true;
> jButtonPause.setText("Pause");
> }
> }
>
> the above is the code for the button. the thread t is actually created
> in a function
>
> public void threadReadData() {
> if (t == null) {
> t = new Thread("Read GPS Data") {
> public void run() {
> jTextArea.setText("");
> .
> .
> .
>
> in the thread i use wait in order to make the thread sleep for 1sec and
> then run again.
>
> And now the problem.. when i press the button i get a
> java.lang.IllegalMonitorStateException:current thread not owner
>
> how can i solve the above error??
>
> Best regards
> Mandilas Antonis
>

 
Babu Kalakrishnan





PostPosted: 2003-10-28 20:20:00 Top

java-programmer >> thread error Mandilas Antony wrote:
> ok.. i managed to pause the thread but i changed the code to this
>
> synchronized (t) {
> t.notify();
> t.wait();
> }
>
> but now the gui freazes too! :(
>

I assume your jButtonPause_mouseReleased method is called from a
mouseReleased event handler, in which case it runs in the GUI thread.
When you call wait() on "t", this will cause the GUI thread to be
suspended till someone calls notify on the same object (t). That's why
the GUI freezes.

What you're trying to achieve here is unclear. Remember that calling
wait() on a Thread object does not cause that thread to wait - it is the
calling thread that goes into the waiting mode. I think a more detailed
reading on Threads and the wait() notify() mechanism is in order. Try
the Java Tutorial from Sun for the fundamentals.

BK

 
 
Mandilas Antony





PostPosted: 2003-10-30 6:14:00 Top

java-programmer >> thread error i have read the tutorial and i misunderstood what wait() function do..
what i try to do here is to "pause" a thread, like using the "suspend"
method, which although now is not availiabe anymore, using sleep i have
to pause a thread for some time, that's why i prefered to use wait.. but
i suppose this was a wrong decission..

best regards
Antony

Babu Kalakrishnan wrote:

> Mandilas Antony wrote:
>
>> ok.. i managed to pause the thread but i changed the code to this
>>
>> synchronized (t) {
>> t.notify();
>> t.wait();
>> }
>>
>> but now the gui freazes too! :(
>>
>
> I assume your jButtonPause_mouseReleased method is called from a
> mouseReleased event handler, in which case it runs in the GUI thread.
> When you call wait() on "t", this will cause the GUI thread to be
> suspended till someone calls notify on the same object (t). That's why
> the GUI freezes.
>
> What you're trying to achieve here is unclear. Remember that calling
> wait() on a Thread object does not cause that thread to wait - it is the
> calling thread that goes into the waiting mode. I think a more detailed
> reading on Threads and the wait() notify() mechanism is in order. Try
> the Java Tutorial from Sun for the fundamentals.
>
> BK
>

 
 
hodren.naidoo





PostPosted: 2007-8-6 19:23:00 Top

java-programmer >> thread error Hi

Can please someone help me with this error?

An error was encountered while publishing this resource.

thread.error

Sorry, a site error occurred.

Traceback (innermost last):

* Module ZPublisher.Publish, line 196, in publish_module_standard
* Module Products.PlacelessTranslationService.PatchStringIO, line
34, in new_publish
* Module ZPublisher.Publish, line 157, in publish
* Module Zope2.App.startup, line 243, in abort
* Module transaction._manager, line 107, in abort
* Module transaction._transaction, line 507, in abort
* Module transaction._transaction, line 580, in abort
* Module Shared.DC.ZRDB.TM, line 64, in abort
* Module Products.ZMySQLDA.db, line 389, in _abort
error: release unlocked lock

Thanks