notifying particular thread to wake up.

R

Rupesh

Is there any way to notify a particular thread to wake up? All the
waiting threads are same priority.

thanks
 
D

Daniel Pitts

Is there any way to notify a particular thread to wake up? All the
waiting threads are same priority.

thanks

Thread scheduling is up to the OS. If a thread is blocked in wait(),
you can use notify() or notifyAll() to unblock it.

I suggest you read Java Concurrency In Practice <http://
www.javaconcurrencyinpractice.com/>. It teaches you everything you
should know before attempting to create multi-threaded programs.

If all your threads are in wait() on the same object, then you'll have
to call notifyAll(), the wait() call should be in a loop (this is
ALWAYS true), the loop can check to see if that particular thread is
the one that should wake up, and if not, go back to waiting.
 
E

Eric Sosman

Rupesh wrote On 09/25/07 17:37,:
Is there any way to notify a particular thread to wake up? All the
waiting threads are same priority.

What are they waiting for?

If they are waiting on condition variables, then yes:
call pthread_cond_broadcast() on all the condvars, which
will cause all the waiting threads to awaken, including
the one you care about (if it was among those waiting).

But perhaps you want to awaken the designated thread
without awakening any others? If so, the answer is no.
Threads waiting on condvars may awaken at any time, with
or without a good reason. You can ensure that at least
one awakens, but you cannot prevent others from doing so,
too.

You could set a variable specifying "Thread T3 should
run" before calling pthread_cond_signal() or _broadcast().
Unintended threads might or might not wake up, but each
can test your variable and go right back to sleep again
unless it's T3.

The interesting question is: Why do you care which
thread wakes up? It usually shouldn't matter.
 
E

Eric Sosman

Eric Sosman wrote On 09/25/07 18:00,:
Rupesh wrote On 09/25/07 17:37,:
Is there any way to notify a particular thread to wake up? All the
waiting threads are same priority.


What are they waiting for?

If they are waiting on condition variables, [...]

Oh, drat: I got my newsgroups mixed up and answered
as if for comp.programming.threads. The answers are really
the same for Java, but the nomenclature is different: for
"waiting on a condvar" read "executing the wait() method"
and for "pthread_cond_signal()" and "_broadcast()" read
"notify()" and "notifyAll()." Sorry about that.
 
H

Hunter Gratzner

Is there any way to notify a particular thread to wake up? All the
waiting threads are same priority.

Do not use threads if you want a controlled sequential execution of
code. Just call the pieces of code one after the other from one thread.
 
N

nebulous99

I suggest you read Java Concurrency In Practice <http://www.javaconcurrencyinpractice.com/>. It teaches you everything you
should know before attempting to create multi-threaded programs.

ALERT! The URL given does not lead to any explanation of Java
concurrency in practise. It leads to an advertisement trying to sell
something.

I recommend the Java Tutorial at java.sun.com; there's a great deal of
information on threading and concurrency in Java to be found there,
and you will not run into any "bait and switch" where a link promises
information but leads to a page that asks you for your money instead.
Instead it will simply lead directly and promptly to the information
itself.

And beware of links posted in this newsgroup; unfortunately this type
of tactic is not infrequent here. Don't waste money; use the free
javadocs, the free Java Tutorial, and Google for other free
documentation before even thinking of actually spending money for
information that's usually easily found online.
 
R

Roedy Green

ALERT! The URL given does not lead to any explanation of Java
concurrency in practise. It leads to an advertisement trying to sell
something.

that "something" is a book with a list of authors including the
venerated Joshua Bloch and Doug Lea.

The registered owner of the site is PEIERLS, TIMOTHY
Prior Artisans, LLC
275 ELDERFIELDS RD
MANHASSET, NY 11030-1625
US

Tim Pierls is the primary author of the book.

The book is most likely is about as good as you could get, and the
site is owned by the author.

The site has additional information:

Table of Contents
View code examples (source jar)
Concurrency annotations: jar, javadoc, source
Sample chapter
Errata
Praise for Java Concurrency in Practice
About the authors

I see nothing wrong with quoting the site. There is nothing wrong
withg getting paid for your efforts. My complaint is when people try
to sell me a defective or irrelevant product.

Here are links to various bookstores if you don't like that site.

http://www.amazon.co.uk/gp/product/...mp=1634&creative=6738&creativeASIN=0321349601
http://search.barnesandnoble.com/bo...sbn=9780321349606&lkid=J12871747&pubid=K49036
http://www.powells.com/partner/28995/biblio/9780321349606
http://www.amazon.com/gp/product/03...mp=1789&creative=9325&creativeASIN=0321349601
http://www.amazon.de/gp/product/032...mp=1638&creative=6742&creativeASIN=0321349601
http://www.amazon.fr/gp/product/032...mp=1624&creative=6746&creativeASIN=0321349601
http://www.jdoqocy.com/click-235804...ers.indigo.ca/books/item/books-9780321349606/
http://www.amazon.ca/gp/product/032...15121&creative=330641&creativeASIN=0321349601
 
L

Lew

ALERT! The URL given does not lead to any explanation of Java
concurrency in practise. It leads to an advertisement trying to sell
something.

Something truly valuable and worth far more than the price you'll pay for it.
I've got this book and I love it. It's fabulous. It's superb. It's
informative. Buy it, everyone.

Or be doomed to mess up your multi-threaded code.

At work I have already secured the value of the book in brownie points from my
managers, and in understanding some of the issues our system has encountered,
and I'm only halfway through the book.

Y'know, it'd be nice if everything were free, but it isn't. Some things cost
money, and there's an argument that money makes civilization more viable. The
point is that some things are worth every penny that they cost, and this book
is certainly one of them.

I bought this book, using my own money, not paid for by an employer or anyone
else (although it is tax deductible), and I am glad I did.
 
L

Lew

Roedy said:
that "something" is a book with a list of authors including the
venerated Joshua Bloch and Doug Lea.

The registered owner of the site is PEIERLS, TIMOTHY
Prior Artisans, LLC
275 ELDERFIELDS RD
MANHASSET, NY 11030-1625
US

Tim Pierls is the primary author of the book.

He's listed second. Brian Goetz is the primary author.
The book is most likely is about as good as you could get, and the
site is owned by the author.

The site has additional information:

Table of Contents
View code examples (source jar)
Concurrency annotations: jar, javadoc, source
Sample chapter
Errata
Praise for Java Concurrency in Practice
About the authors

I see nothing wrong with quoting the site. There is nothing wrong
with getting paid for your efforts. My complaint is when people try
to sell me a defective or irrelevant product.

Amen, brother!

Buy it.
 
N

nebulous99

Something truly valuable and worth far more than the price you'll pay for it.

[snip remainder of endorsement]

(This response applies equally to Roedy's.)

Regardless of all of that, it remains the case that the original post
is a bait-and-switch. It purports to link to information about Java;
instead it links to an advertisement. It's a clear grab for money.
Regardless of how relevant or well-targeted the ad might be in this
context, it is still an ad, and all of the following occurred:

* The first response to the thread was an ad for a commercial product.
* The response did not disclose that this was the case; instead one
had to follow the link to discover that one is being asked for money
instead of merely receiving an answer.
* The response conspicuously did not mention the Java Tutorial or any
of the other copious free material on the subject matter, which the OP
would be financially well-advised to consider first before resorting
to paying money.
* There's also the niggling little matter that the ad is probably
utterly useless to anyone who isn't an American with a credit card
from one of the Big 3 anyway. That's about 1% of the world population.
If you're a German with poor credit but a $50 bill (well, fifty euro
or whatever) burning a hole in your pocket, too bad, your money isn't
green enough I expect.

Regardless of the OP's motives and intentions, the result is awfully
shabby.

And Usenet is not an appropriate place for commercial advertising
anyway.
 
R

Roedy Green

It's a clear grab for money.

It is then up to you to explain how Daniel gets money for recommending
the book. Given the reputation of the authors, especially Doug Lea,
Mr. Threads, that is the best possible book to read on the subject.
THAT is why he recommended it.

Daniel used the same language one would use to recommend a book. There
was no attempt to trick you into thinking you would get something free
and ambushing you. It not as if he lured you to expend 4 hours
getting to his vacuum cleaner store.

Even if he did get a referral fee, he has done nothing to harm you. He
has pointed you to the best source of information on the topic. He
did not defraud you of any money.

If he pointed you to some spyware installing site, or to a book
nothing do to with threads, or to a crap book that was useless, I
would join you in bashing him. BUT HE DIDN'T. He answered your
question pointing you to the prime source of information about the
book.
 
Joined
Sep 26, 2007
Messages
2
Reaction score
0
NO way to call a perticular thread from wainting state

listen,wen we call notify(),only one thread(any thread in waiting state depends on OS or thread manager{i m not sure}) comes out frm waiting state. solution is ==> Always use notifyAll(). it releases all the threads. thread that has lock on object, wll get resource. dats y we always keep wait() & notify() methods in sychrinized block.
remember always.
=> wait()method, always go into waiting state before releaseing resource whtin sychronizations block by which nobdy can access direclty as wl
 
D

Daniel Pitts

Something truly valuable and worth far more than the price you'll pay for it.

[snip remainder of endorsement]

(This response applies equally to Roedy's.)

Regardless of all of that, it remains the case that the original post
is a bait-and-switch. It purports to link to information about Java;
instead it links to an advertisement. It's a clear grab for money.
Regardless of how relevant or well-targeted the ad might be in this
context, it is still an ad, and all of the following occurred:
Actually, I have know vested interest in that book. I just thought it
was a good book, and rather than simply provide the OP with *only* the
name of the book, I did a quick google and found that they had an
official website.
* The first response to the thread was an ad for a commercial product. My response was appropriate.
* The response did not disclose that this was the case; instead one
had to follow the link to discover that one is being asked for money
instead of merely receiving an answer.
Oh, I wasted one click! I'm so sorry. Deal with it.
* The response conspicuously did not mention the Java Tutorial or any
of the other copious free material on the subject matter, which the OP
would be financially well-advised to consider first before resorting
to paying money.
I was not aware that the Java tutorial went into the kind of detail
that JCIP did.
* There's also the niggling little matter that the ad is probably
utterly useless to anyone who isn't an American with a credit card
from one of the Big 3 anyway. That's about 1% of the world population.
If you're a German with poor credit but a $50 bill (well, fifty euro
or whatever) burning a hole in your pocket, too bad, your money isn't
green enough I expect.

Regardless of the OP's motives and intentions, the result is awfully
shabby.

And Usenet is not an appropriate place for commercial advertising
anyway.
This is the second time you've accused me of commercial advertising
when I don't make money from anything I do on usenet.

Although, I don't see the problem if I do. Some newsgroups aren't
appropriate places for commercial advertising, but pointing out an
*extremely* relevant product is valud.

God, this is like the time everyone told you to check out ANT and you
refused to even *google* for it!

Twisted, you are WRONG!
 
M

Mike Schilling

Daniel said:
This is the second time you've accused me of commercial advertising
when I don't make money from anything I do on usenet.

Yeah, it accused me of the same thing when I recommended IntelliJ as
superior to Eclipse and NetBeans. Don't let it worry you; the rest of us
know better.
 
R

Rupesh

Yeah, it accused me of the same thing when I recommended IntelliJ as
superior to Eclipse and NetBeans. Don't let it worry you; the rest of us
know better.

Hello geeks,

What's happening... let's come back to problem. The Problem is the
threads are not of same class. They are the threads from different
classes that need to access some shares resources. I have used block
synchronized but I am not getting things right. So what do you suggest
me to do in such condition. They I have to synchronize threads from
different classes.
 
M

Mike Schilling

Rupesh said:
What's happening... let's come back to problem. The Problem is the
threads are not of same class. They are the threads from different
classes that need to access some shares resources. I have used block
synchronized but I am not getting things right. So what do you suggest
me to do in such condition. They I have to synchronize threads from
different classes.

Synchronize on the resource, not on the thread instance.
 
D

Daniel Pitts

Yeah, it accused me of the same thing when I recommended IntelliJ as
superior to Eclipse and NetBeans. Don't let it worry you; the rest of us
know better.

Yeah, actually, that was the other thing. I did suggest IDEA at some
point, and got accused of the same thing.

It really makes me wonder why anyone believes everything should be
free? If someone asked me how to make a salad, and I suggested going
to a Safeway to pick up some lettuce, would it be such a surprise when
they got to the checkout line and *gasp* someone asked for money?

Very little in life is truly free. While I agree more things *should*
be, I'm perfectly willing to suggest useful commercial things,
regardless of the amount of money I get from it.

Although, I do recommend that book (and Refactoring by Fowler, and
Refactoring to Patterns by Kerievsky) often enough that I should
consider getting some sort of paid referral link for them :)

Thanks for the idea Twisted. You're right, I should make money off of
Usenet.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top