Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2006

Tip: Looking for answers? Try searching our database.

[thread][eclipse] how to check

Thread view: 
Thomas Richter - 10 Oct 2006 10:21 GMT
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
Thomas Weidenfeller - 10 Oct 2006 10:56 GMT
> 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
Signature

The comp.lang.java.gui FAQ:
http://gd.tuwien.ac.at/faqs/faqs-hierarchy/comp/comp.lang.java.gui/
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq

TechBookReport - 10 Oct 2006 11:44 GMT
>> is there a smart way to check whether an application is thread
>> save? My object are not accessed from different points and all
[quoted text clipped - 15 lines]
>
> /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

Signature

TechBookReport Java http://www.techbookreport.com/JavaIndex.html

opalpa opalpa@gmail.com http://opalpa.info - 10 Oct 2006 13:24 GMT
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
opalpa@gmail.com
http://opalpa.info/
Thomas Richter - 10 Oct 2006 13:47 GMT
opalpa opalpa@gmail.com http://opalpa.info schrieb:
> http://javapathfinder.sourceforge.net/ attempts to discover concurancy
> Using tools helps.

Of which tools do you think?

> > My object are not accessed from different points and all
> > static methods are syncronized.
> Non-static methods too.

Even if my threads will not access the same objects?

wkr Thomas
opalpa opalpa@gmail.com http://opalpa.info - 10 Oct 2006 14:02 GMT
> opalpa opalpa@gmail.com http://opalpa.info schrieb:
> > http://javapathfinder.sourceforge.net/ attempts to discover concurancy
> > Using tools helps.
>
> Of which tools do you think?

Other than pathfinder, FindBugs find some concurancy problems.

> > > My object are not accessed from different points and all
> > > static methods are syncronized.
> > Non-static methods too.
>
> Even if my threads will not access the same objects?

What about in the future?  Not necessarily even on your current
project.

opalpa
opalpa@gmail.com
http://opalpa.info/
Thomas Weidenfeller - 10 Oct 2006 14:42 GMT
> 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
Signature

The comp.lang.java.gui FAQ:
http://gd.tuwien.ac.at/faqs/faqs-hierarchy/comp/comp.lang.java.gui/
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq

opalpa opalpa@gmail.com http://opalpa.info - 10 Oct 2006 15:31 GMT
> (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
opalpa@gmail.com
http://opalpa.info/


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.