Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Pausing Threads From Events

Reply
Thread Tools

Pausing Threads From Events

 
 
Carl Howells
Guest
Posts: n/a
 
      04-28-2004
Bryan R. Meyer wrote:

> I appreciate the help. I don't quite understand the response given by
> NOBODY. This is not for a professional project; it is merely for a
> small personal project. I can't understand why such a function for
> pausing threads is not already in the language. (Of course, I noted
> the deprecation of suspend().)


I can explain this one... But I may not need to. You say that you
noted that suspend() is deprecated. But did you read the rather large
document Sun put together explaining why many of the methods in Thread
are deprecated? It explains rather well.

As a simple recap, suspend() is dangerous. If you can arbitrarily
suspend another thread at any point in its execution, you can create
deadlocks. Requiring that the thread implement code to pause itself
safely (releasing all necessary locks, and making sure all data
structures it was using are in internally consistent states) increases
the safety of the threading system significantly.
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      04-29-2004
On 28 Apr 2004 14:19:23 -0700, http://www.velocityreviews.com/forums/(E-Mail Removed) (Bryan R.
Meyer) wrote or quoted :

> I can't understand why such a function for
>pausing threads is not already in the language.


There was, then they discovered it did not always work. So they
deprecated it all.

You can try something like StoppableThread.

See http://mindprod.com/products.html#BUS
part of the business package.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      04-29-2004
On Wed, 28 Apr 2004 15:30:05 +0100, Ade wrote:

> Is it really necessary to criticize other people's solutions?


Is it really necessary to repost 197
lines of the former post to ask that?

Please have a look over the entry after 'top-post'
<http://www.physci.org/codes/javafaq.jsp#netiquette>

While we are on the subject, and
in answer to your question.

"Yes"

This is a technical group (checks)
OK - I realise now it is going to
both c.l.j.programmer _and_ c.l.j.help

That complicates things..

Such 'rough and tumble' comments would usually
go by on c.l.j.p without raising a single
eyebrow, but converstaions on c.l.j.h are
usually conducted in a much more sensitive
manner.

Ultimately though, most people come to
the groups to get the best possible solution,
rather than to have a nice, polite chat.

In defence of the specific statement
"I'm sorry to tell you the following but
you should mostly ignore the answers you got.
These techniques are not professionnal. Period."

There are times you need to make a definitive
statement, at the top of the post, that other
solutions offered (no matter how well intentioned)
are not the way to go.

( And as far as 'polite' goes, I do not see
how you could both achieve the 'definitive
statement' and be any more polite.. )

If you have any particular disagreements with
technical aspects of the code provided, discuss
them, otherwise celebrate that you have now
been shown some extra tips.

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      04-29-2004
On Wed, 28 Apr 2004 15:09:18 +0100, Rob Shepherd
<(E-Mail Removed)> wrote or quoted :

>> I'm sorry to tell you the following but you should mostly ignore the
>> answers you got. These techniques are not professionnal. Period.

>
>So only Java "Professionals" are allowed to post messages with fully working
>endorsed guaranteed to work *this-what-you-MUST-do* code examples eh?


keep in mind this is comp.lang.java.help THE place for newbies. Cut
everyone some slack.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      04-29-2004
On Wed, 28 Apr 2004 15:30:05 +0100, Ade <(E-Mail Removed)> wrote or
quoted :

>Is it really necessary to criticize other people's solutions?

YES YES YES. If people post code everyone should be pointing out ways
to improve it. People learn from copying. If you let sloppy code
pass, you teach sloppy coding. However, there is no need to be nasty.

Engineers and computer scientists have to learn to get ego out the
way. You NEED peer review to get the bugs and and to improve.

Thin skinned people can never become great programmers.

Think of it as a game to polish each bit of code that gets posted to
perfection.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
Knute Johnson
Guest
Posts: n/a
 
      04-29-2004
NOBODY wrote:
> Yes, I got answers for you.
> I'm sorry to tell you the following but you should mostly ignore the
> answers you got. These techniques are not professionnal. Period.
>
> 1st, you sure will have a boolean to change/check somewhere, but
> the volatile keyword (that supposably protects threads from processor
> caching) is not implemented in many jvm. You may easily confirm that hot
> topic with a simle search on the web.
>
> 2nd, the only sure way to do "messaging" between threads required the use
> of a "synchronized" zone, that forces the thread fo resync with memory.
> This is critical in multiprocessors platforms.
>
> 3rd, your thread to be paused need to cooperate, i.e. it must be ready to
> be notified or capable to handle interruptions (only one of the 2
> technique is enough, and I suggest you go with notifiations, it is less
> work, although you might want to combine both)


Why would you use a non-compliant JVM or are we talking the 'Dark Side'
here? The use of volatile that I suggested would I believe work just
fine as it would not be affected by any of the known memory reordering
issues. Bryan asked how to communicate the pause message from his
MouseListener to his running thread. There is nothing unprofessional
about setting a flag to do that. He didn't define what he meant by
pause and could have just wanted to sleep for a few milliseconds.

Your PauseableLoopThread, while a brilliant and professional masterpiece
of Java coding, is probably serious overkill for what Bryan needed.

--

Knute Johnson
email s/nospam/knute/
Molon labe...
 
Reply With Quote
 
NOBODY
Guest
Posts: n/a
 
      04-30-2004
I'm sorry Knute, Rob, Ade.
I didn't meant to offend you.

Thanks Roedy, Andrew.
I also feel some groups are dedicated to experts, because, unlike newbies,
we can't find books and hundreds of web pages to tell us the answer at
chapter 2.


>I thought the beauty of Java was that there are so many different ways
>to do things - and no single way is better than all others, it's simply
>different.


Well, that is just not true. And java has nothing to do with it. This was
about concurrent programming, not swing GUIs.

Besides, experts usually end up sharing the same vision for an
architecture/implementation because they learned the do's and don't of
programming. This forum helps accelerate the process.


I wanted to be precise and underline some threading issues by the same
medium. Judging by some critics, I didn't miss my goal...!

I mostly wanted to underline that no one should wait() without using notify
()/notifyAll(), and Thread.sleep() should not even exist. There is nothing
worse (relatively speaking) than a thread stuck somewhere ureachable...

 
Reply With Quote
 
 
 
Reply

Thread Tools

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pausing and Unpausing Threads Aaron J. M. Python 6 08-13-2007 01:50 PM
Wireless keeps pausing =?Utf-8?B?Q3VydF9DIFtNVlBd?= Wireless Networking 0 10-20-2005 01:57 AM
Events Events Events Please Help Chris ASP .Net Web Controls 0 08-30-2005 08:21 PM
Pausing a program - poll/sleep/threads? Simon John Python 12 02-21-2005 12:52 AM
Pausing a Swing Worker Thread? C-man Java 2 09-18-2004 08:19 PM



Advertisments