Thread.stop makes thread unabled to be signalled

B

Benji

Roedy said:
Of course. But it does not matter. You give them a low grade. Your
system can still recover, albeit more awkwardly by killing the entire
jvm.

Ok, well, while I might agree with you, I'm a TA trying to write a system
for professors who may or may not agree with that grading policy. I'm
not looking for an argument against their grading philosophy, I'm looking
for a technical solution to the problem.
 
B

Benji

Chris said:
Yep. If you read about why Thread.stop() is deprecated, you'll see that
its unavoidable potential to cause deadlocks in native code is one major
reason. Ending that thread is not necessarily good enough. You're
still taking a big chance.

Alright. Well, thanks for the reply. *sigh* =)
 
B

Benji

Roedy said:
You would not talk to a police officer, your prof, even a grocery
clerk that way you little twerp.

But, then again, police officers, my professors, and even my grocery
clerks have better understandings of social situations, and wouldn't
have gotten upset by an attribution line in the first place. :eek:)
You will not get any help from me again unless you trick my killfile
filter and I fail to notice.

You know, when I was a freshmen in college, and had just discovered what
a killfile was, I too thought it was cool to make one last "I'm putting
you in my killfile" post before kfing them.

Sorry if I upset you in all of this, but you have to realize that at your
age, you should learn a little more grace in how to handle situations
that upset you. For example, if you had e-mailed me rather than posting
to the newsgroup, I might have taken it a little more seriously - but as
it is, your post was clearly intended to get attention and to make you
look cool, although I'm afraid that you were mistaken on the last point.
 
L

Luc The Perverse

Benji said:
Nope. First time in 4 years that I've had anyone get upset about that
attribution line. I had a professor pretend he was upset about it just
to see how I would react. =) (not *that* was funny...)

I personally was very offended, which I consider just cause for petitioning
for an amendment to The Constitution of the United States of America to
illegalize diminuitive usenet attribution lines. Usenet respect ~is~ the
foundation of our society; my home bible teacher told me so; and I feel that
in order for our society to not crumble, we need to take steps now to end
this insult to our very existence..
 
S

steve

You might find that cute. I don't.

When I was teaching on a government funded project to teach programming to
the jobless , drug addicts , and other under performing social groups.
White board markers were the highlight of everyones day , including mine.
Ahhh, fond memories.


But rodders has a point, that as part of the course, if your students cannot
follow a simple task , such as a call out ,then they are not going to be very
good programmers in a team.
The other solution is to allocate marks , and force them to to extend one of
your classes.
Then make them implement the exit function , if they do not fit into your
framework the program will not run ,so they fail the task.

Seve
 
B

Benji

steve said:
But rodders has a point, that as part of the course, if your students cannot
follow a simple task , such as a call out ,then they are not going to be very
good programmers in a team.
The other solution is to allocate marks , and force them to to extend one of
your classes.
Then make them implement the exit function , if they do not fit into your
framework the program will not run ,so they fail the task.

Well, again, I would love to be able to force them to do this, but it's
not really that simple. I'm looking for a good technical solution that
allows the professor to decide what the policy should be.

My current idea is that instead of calling stop, I should
1) suspend the thread
2) get a stack trace, make sure it's in student code (not system code)
3) if it's in student code, kill it. Otherwise, resume the thread and
try again a set number of times. (I doubt that the deadlock situation
really applies if all I'm doing is calling suspend and getStackTrace)

As long as it's in student code, I only risk screwing up their state, not
system state.

any thoughts?
 
R

Roedy Green

In my country when you up to a stranger and insult him it means that
you want to scuffle. Given the distance limitation, I can't interpret
it that way.

It is perhaps a cultural thing. My dad was waiting in a queue in
England and lightly brushed the person next him in line with his
elbow, something of no importance in Canada. The person turned and in
icy tones said, "There is no need to jostle".

Whether Benji considers it offensive is irrelevant. I do, and he is
addressing his insult to me, and he still expects me to do him a
favour even after I asked him to desist, and he made a point of
repeating the insult.

It is terminal stupidity. He gains nothing by his behaviour. It is
not as if he were a troll TRYING to annoy others. He is trying to
elicit aid from them.

Perhaps it is a habit he picked up from American sitcoms who rely on
cheap insult humour because can't afford writers who can think of
dialog that is truly funny.

On the other paw, there is a saying by the late Ken Keyes.

"You add suffering to the world just as much when you take offense as
when you give offense."

So I think my optimal strategy is to refuse to help Benji in future,
explain why, and not sweat it.

There is another poster who uses a similarly insulting intro. I asked
him to stop. He refused. I dropped the issue, since he is the one
giving me information most of the time, not the reverse.
 
S

steve

Well, again, I would love to be able to force them to do this, but it's
not really that simple. I'm looking for a good technical solution that
allows the professor to decide what the policy should be.

My current idea is that instead of calling stop, I should
1) suspend the thread
2) get a stack trace, make sure it's in student code (not system code)
3) if it's in student code, kill it. Otherwise, resume the thread and
try again a set number of times. (I doubt that the deadlock situation
really applies if all I'm doing is calling suspend and getStackTrace)

As long as it's in student code, I only risk screwing up their state, not
system state.

any thoughts?

if you are going to try to persist with this , the only other things I can
suggest are:
1. "reflection & "extend" their class then run it in a thread with a
timeout.
2. run their program in debug mode in the JVM, then use the pre-provided
hooks in the JVM, the same way a debugger written in java does.

But trying to use "stop" or other depreciated methods , is really asking for
it. if not now then some time in the future.

Steve
 
S

steve

In my country when you up to a stranger and insult him it means that
you want to scuffle. Given the distance limitation, I can't interpret
it that way.

It is perhaps a cultural thing. My dad was waiting in a queue in
England and lightly brushed the person next him in line with his
elbow, something of no importance in Canada. The person turned and in
icy tones said, "There is no need to jostle".

Whether Benji considers it offensive is irrelevant. I do, and he is
addressing his insult to me, and he still expects me to do him a
favour even after I asked him to desist, and he made a point of
repeating the insult.

It is terminal stupidity. He gains nothing by his behaviour. It is
not as if he were a troll TRYING to annoy others. He is trying to
elicit aid from them.

Perhaps it is a habit he picked up from American sitcoms who rely on
cheap insult humour because can't afford writers who can think of
dialog that is truly funny.

On the other paw, there is a saying by the late Ken Keyes.

"You add suffering to the world just as much when you take offense as
when you give offense."

So I think my optimal strategy is to refuse to help Benji in future,
explain why, and not sweat it.

There is another poster who uses a similarly insulting intro. I asked
him to stop. He refused. I dropped the issue, since he is the one
giving me information most of the time, not the reverse.

:) A "scuffle", is that the polite way to say a "smack on the nose".
Well I'm from England and I can say we take Queueing very seriously, any
sort of body contact is classed as a "jostle".
whereas here in China there is no such thing as a queue, you cannot even
wait in line to get OFF a bus ,without some MOFO trying to climb over you.
Queues only exist here as enforced structures marked out with Electric
Battons.

Steve
 
P

pkriens

I am not sure I fully understand your problem. This "thread" goes off
in all kind of directions (which is not uncommon here) except
discussing the problem you raise :-(

Though stop is deprecated, I think the reasons are overly politically
correct. If the reasons were valid, then any unchecked exception are
mortal. From my experience, this leaves very few systems. One of the
good parts of Java is that it does not die when it gets in a bad state.
Especially in cases like you discuss where no lifes or great finanical
risks are at stake, Thread.stop can have a role. I think SUN, as a
litigatious sensitive company, deprecated it (though it has NOT removed
it!).

I understand your key problem is that your notification is not waking
up the wait. I deduce that you you run the student code in a
try/finally clause and notify in the finally clause you so your main
thread wakes up? I.e. something like this:

public class Runner extends Thread {
Runnable student;
static Timer timer = new Timer();

Runner(Runnable student) {
this.student = student;
}

public void run() {
try {
student.run();
}
finally {
synchronized (this) {
System.out.println("Notifying");
notifyAll();
}
}
}

public static void main(String args[]) throws Exception {
Runnable student = new BadStudent();

final Runner runner = new Runner(student);
TimerTask task = new TimerTask() {
public void run() {
System.out.println("Timed out, stopping");
runner.stop();
}
};
timer.schedule(task, 5000);
System.out.println("Starting runner");
runner.start();
synchronized (runner) {
runner.wait();
System.out.println("Received notification");
}
task.cancel();
}
}

class BadStudent implements Runnable {
double sum;
public void run() {
System.out.println("Starting bad student");
try {
double start=1;
while (true ) {
start /= 2;
sum += start;
}
} finally {
System.out.println("Leaving bad student");
}
}
}
Running it:
Starting runner
Starting bad student
Timed out, stopping
Leaving bad student
Notifying
Received notification

I tried this on my system and it works ok. Can you elucidate what you
do different? Show some code? Did I misunderstand you?

Running the code in a Threadgrouped Thread, its own classloader, and
then using stop for this example should give you a system that can
handle most of the student's abuses. You could even deny catching
ThreadDeath which is an easy trick.

An alternative is to use Aspect Oriented Programming. You could write
aspects that insert checks in the students code to quit in every method
and loop (I am not sure if you write an advice for a loop though). You
could also use ASM and just insert a check before every jump I guess.

Kind regards,

Peter Kriens
OSGi Evangelist
www.osgi.org and www.aqute.biz
 
C

Chris Uppal

Benji said:
My current idea is that instead of calling stop, I should
1) suspend the thread
2) get a stack trace, make sure it's in student code (not system code)
3) if it's in student code, kill it. Otherwise, resume the thread and
try again a set number of times. (I doubt that the deadlock
situation really applies if all I'm doing is calling suspend and
getStackTrace)
[...]

any thoughts?

It sounds as if you are contemplating a system that is
a) overcomplex
b) unreliable
c) less safe than it could be

-- chris
 
B

Benji

pkriens said:

Well, darn. I typed up a fairly long response to your post, and vim
went and barfed on itself. Anyway, I was just going to say that
I found the problem from trying to modify your code. The thread that is
stopped throws an InterruptedException if it tries to wait(). However,
that only gets thrown once, so after that I think I can carry on as usual.

As for your suggestions about threadgrouping, classloaders, and denying
catches, I've done the last two - but of what importance is threadgrouping?

Also, I think your comment about injecting checks before jumps and method
calls is a darn good idea, and I will definitely look in to doing that
instead of my previous plan.

Thanks for your time. =)
 
T

Thomas Hawtin

pkriens said:
Though stop is deprecated, I think the reasons are overly politically
correct. If the reasons were valid, then any unchecked exception are
mortal. From my experience, this leaves very few systems. One of the
good parts of Java is that it does not die when it gets in a bad state.
Especially in cases like you discuss where no lifes or great finanical
risks are at stake, Thread.stop can have a role. I think SUN, as a
litigatious sensitive company, deprecated it (though it has NOT removed
it!).

Quite often unchecked exceptions don't result in a stable state. You can
claim this is a code quality issue, but there are a couple cases of
exception-unsafety in the collection classes. If Joshua can't ensure it
is correct, then there isn't much hope for the rest of us.

Thread.stop is worse than almost all other unchecked throwings in that
it is an asynchronous throw. It can occur where really no exception
should be possible. In some situations it is very handy to be able to
copy over multiple references, say, and it either succeeding fully or
failing without side-effect.

Other than virtual machine bugs, the only other situation I can think of
where this happens is involved with NIO buffers. Under Linux it just seg
faults instead.

Tom Hawtin
 
P

pkriens

Threadgrouping is necessary so you can catch any student that tries to
spawn other threads. Any thread in a thread group can only create
threads in that group so you can kill ALL their threads.

Kind regards,

Peter Kriens
OSGi Evangelist
www.osgi.org and www.aqute.biz
 
P

pkriens

I agree that the sync nature of stop can cause havoc. However, I think
this is a quite normal state for virtually all larger applications I
have seen. I think it is a fallacy that type safe applications are
safe; there is just too much that can go wrong in software. I have been
working in this industry for over 25 years working for many large and
small companies as consultant, often having to do reviews of large
systems. It is amazing how bad most software is while it still works
for the user.

As always, there are no easy rules; it depends on the risk you run when
it fails. if you do the brakes of a car, do not use java and if you are
dumb enough to do this stop() is not going to make a big difference
overall because you are already screwed. If you write an application
evaluator like Benji, the risk of something bad happening is ok, nobody
will get harmed. Note that there is already something bad happening
because the application does not quit in time, which is part of its
contract.

Concluding: The concerns of stop() are valid for application areas
where you better know the consequences of a myriad of details. This is
not the area where Java shines.

Peter Kriens
OSGi Evangelist
www.osgi.org and www.aqute.biz
 

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,776
Messages
2,569,602
Members
45,185
Latest member
GluceaReviews

Latest Threads

Top