Question on JCIP annotations

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Question on JCIP annotations

Holger Hoffstätte-2

While adopting the JCIP annotations I've come across quite a few "utility
classes", i.e. classes that only contain static methods and no
mutable/visible/published state. Is this considered to be @Threadsafe or
@Immutable? I guess both but that was probably not the intention. :^)

thanks
Holger

_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|

Re: Question on JCIP annotations

tpeierls
We were trying to keep the number of annotations to a minimum, otherwise this would have been called @Stateless.

How about this:

@ThreadSafe // because stateless
public class Util {
}

--tim

On 10/11/06, Holger Hoffstätte <[hidden email]> wrote:

While adopting the JCIP annotations I've come across quite a few "utility
classes", i.e. classes that only contain static methods and no
mutable/visible/published state. Is this considered to be @Threadsafe or
@Immutable? I guess both but that was probably not the intention. :^)

thanks
Holger


_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|

Re: Question on JCIP annotations

Holger Hoffstätte-2
Tim Peierls wrote:
> We were trying to keep the number of annotations to a minimum, otherwise
> this would have been called @Stateless.

Agreed - I realize it's a corner case and just wanted to ask for some
clarification (with an eye towards Findbugs). @ThreadSafe makes more sense
when @Immutable implies multiple objects.

thanks
Holger
_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|

Re: Question on JCIP annotations

Brian Goetz
> Agreed - I realize it's a corner case and just wanted to ask for some
> clarification (with an eye towards Findbugs). @ThreadSafe makes more sense
> when @Immutable implies multiple objects.

Also, bear in mind that a class with static methods only might still not
be thread-safe if they have shared mutable state that is not properly
synchronized.  For example:

@NotThreadSafe
public class FooFactory {
   private static int fooCount;

   public static Foo newFoo() {
     ++fooCount;
     return new Foo();
   }

   public static getFooCount() { return fooCount; }
}
_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest