[thread][eclipse] how to check

T

Thomas Richter

Hi group,
is there a smart way to check whether an application is thread
save? My object are not accessed from different points and all
static methods are syncronized. I used \W[A-Z]\w+\s?\.\w+\(
to find all calls to static function, but I think I have to check
also other method calls ....

wkr Thomas
 
T

Thomas Weidenfeller

Thomas said:
is there a smart way to check whether an application is thread
save? My object are not accessed from different points and all
static methods are syncronized. I used \W[A-Z]\w+\s?\.\w+\(
to find all calls to static function, but I think I have to check
also other method calls ....

You work with a fare to simple idea of how threads work. Just
synchronizing all methods (static or not) does not give you a thread
save application.

You need to understand your code and the potential flow of control
through it to identify critical sections of code. No tool in the world
can do this. This is one of the reasons why threads are not for laymen.
You really have to know what you are doing.

Go back to square one. Get a good book about Java threading and start
reading it.

/Thomas
 
T

TechBookReport

Thomas said:
Thomas said:
is there a smart way to check whether an application is thread
save? My object are not accessed from different points and all
static methods are syncronized. I used \W[A-Z]\w+\s?\.\w+\(
to find all calls to static function, but I think I have to check
also other method calls ....

You work with a fare to simple idea of how threads work. Just
synchronizing all methods (static or not) does not give you a thread
save application.

You need to understand your code and the potential flow of control
through it to identify critical sections of code. No tool in the world
can do this. This is one of the reasons why threads are not for laymen.
You really have to know what you are doing.

Go back to square one. Get a good book about Java threading and start
reading it.

/Thomas
Java Concurrency In Practice, by Brian Goetz, should be that book. It's
excellent - see the review here: http://www.techbookreport.com/tbr0261.html
 
O

opalpa opalpa

http://javapathfinder.sourceforge.net/ attempts to discover concurancy
problems. Pathfinder was created at NASA for things like Java on
rover.
is there a smart way to check whether an application is thread
save?

Using tools helps.

Avoiding settors in classes makes it easier to proove they are safe.
My object are not accessed from different points and all
static methods are syncronized.

Non-static methods too.

Will your code potentially ever be accessed by multiple threads? It
takes alot of thinking to check a lot of classes and be confident the
code behaves correctly in such circumstances.

Are there fields that are non-private? Taking a monitor by
synchronizing a method does not give a monitor for instance variables.

All Swing creation and modification is to happen on Swing thread.
I used \W[A-Z]\w+\s?\.\w+\(
to find all calls to static function, but I think I have to check
also other method calls ....

Why just static methods?

opalpa
(e-mail address removed)
http://opalpa.info/
 
T

Thomas Weidenfeller

opalpa said:
Using tools helps.

Only so much. Show me the tool that gives the right answer in the
following rather simple case:

public class SomeClass {
private int someValue;
private int anotherValue;

public synchronized void setSomeValue(int v) {
someValue = v;
}

public synchronized void setAnotherValue(int v) {
anotherValue = v;
}

public void setValues(int a, int b) {
setSomeValue(a);
setAnotherValue(b);
}

...
...
...
}

Question: Is it ok if multiple threads use setValues() concurrently?

(a) If your tool says no, I will argue it might be safe.

(b) If your tool says yes, I will argue it might be unsafe.

(c) If your tool says "I don't know, it depends. You need to check". I
will say thank you very much, I knew that before.

/Thomas
 
O

opalpa opalpa

(c) If your tool says "I don't know, it depends. You need to check". I
will say thank you very much, I knew that before.

Most projects have more than one class. When a tool can go through an
entire source base or entire jar worth of classes and present select
sections for review it helps me.

opalpa
(e-mail address removed)
http://opalpa.info/
 

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,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top