Null pointer exception problem

P

Patricia Shanahan

Chris said:
Out of curiosity, what are the "levels" of thread-safety in that convention ?
Sun's server was taking several minutes to follow each link when I looked for
the malloc() documentation, so I didn't try to find a direct statement in the
their documents.

Unfortunately, I have not found a way of forming a URL for a deep point
in the documentation. Here are the levels, with my summary of the
meanings. Quoted material is copied from the web page.

Safe - functionally OK, but may be poor performance, such as a library
that treats all its code as a single critical region.

Unsafe - "An Unsafe library contains global and static data that is not
protected."

MT-Safe - "An MT-Safe library is fully prepared for multithreaded
access. It protects its global and static data with locks, and can
provide a reasonable amount of concurrency."

Async-Signal-Safe - Safe to call from signal handlers.

MT-Safe with Exceptions - See notes

Safe with Exceptions - See notes

Fork1-Safe - does proper lock clean-up for forking.

Cancel-Safety - safe to use with pthread cancel.

I don't claim these are the right classifications for Java. I don't
think, for example, that it would be a good idea to invoke Java code
inside a signal handler.

How about these:

Unsafe: All accesses should be synchronized externally. May modify
static data without synchronization.

Object-unsafe: Any static data access is synchronized, but caller is
responsible for ensuring instance methods only run in one thread at a
time. Can be done either by calling instance methods for a given object
in only one thread, or by synchronizing all instance method calls for a
given object on that object.

Safe: Only needs external synchronization to achieve consistency between
multiple calls.

Event-thread-only: Use in event handling thread only. (Most of Swing
would be designated Event-thread-only).

Patricia
 
P

Patricia Shanahan

Chris said:
I have to recant: I thought I had such an example, but now I look again, all
the (relevant) methods of AbstractList /are/ overriden in Vector.

I don't think you should need to grub through the sources to find the
answer to a basic question about external functionality.

Patricia
 
L

Lew

Patricia said:
I don't think you should need to grub through the sources to find the
answer to a basic question about external functionality.

From
Unlike the new collection implementations, Vector is synchronized.

No grubbing in source required.
 
A

a24900

How about these:

Some classes in the API require to acquire a central lock, via a
mechanism provided by the class. E.g.
http://java.sun.com/javase/6/docs/api/java/awt/Component.html#getTreeLock()

Also, there are classes where a combination of methods is save, while
other combinations are not. So:
Object-unsafe: Any static data access is synchronized, but caller is

....

Partly-save: Only one or more particular sets of methods are thread
save when used in combination.

Save-if-procedure-followed: Caller is responsible for following an
outlined procedure. Instances are thread-save if procedure is
followed.

Partly-save-if-procedure-is-followed: Caller is responsible for
following an outlined procedure. A a particular set of methods is
thread-save if procedure is followed.
Safe: Only needs external synchronization to achieve consistency between
multiple calls.
Event-thread-only: Use in event handling thread only. (Most of Swing
would be designated Event-thread-only).

Maybe in more generic terms:

Designated-thread-only: Use in a designated thread only.

But qualifying a class/instances is not enough. Each method also needs
to be qualified individually. The class defines a convenient scope for
looking at a set of methods, but statements on class level can only
apply to how the methods interact as a whole. Particularly for partly-
save classes per-method information is needed. E.g. UML has
sequential (not thread save), guarded (thread save, but one active
thread at a time only, others are blocked), and concurrent (thread
save, multiple threads at a time execute in parallel) methods.

That still doesn't cover all cases. E.g. cases where a method
invocation waits for a certain time until a lock becomes available and
prematurely returns if it doesn't, aren't covered.

But anyhow, it will be a cold day in hell when Sun starts to qualify
classes and methods.
 
M

Mike Schilling

Patricia Shanahan said:
I don't think you should need to grub through the sources to find the
answer to a basic question about external functionality.

You don't; that all the public methods of Vector are synchronized is fully
documented.

I could try to blame Sun for the fact that I felt it necessary to verify
this by hand, but that wouldn't be entirely fair :)
 

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

Similar Threads


Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,252
Latest member
MeredithPl

Latest Threads

Top