synchronized static method -is there a problem?

Hi.

I'm facing a problem. I have a common java class that is used by many applications. Class is in a jar file and is in server's shared library. And every applications in the server used it.

Methods are declared static but notsynchronized static. Class itself is not static. I have found that sometimes right after server is restarted and applications are using this class, method return values are mixed up or method behaviour is strange. I havent able to repeat this problem when testing with just one application.

Is the problem static method and when using under one classloader (in shared lib) probelm occurs? So if i declare it static synchronized, does that solve my problem?

[720 byte] By [basti78a] at [2007-11-27 5:04:43]
# 1
Synchronization problems occur over contending use of fields, not methods and not local variables.Check any fields that your methods modify, especially if a field is beiing modified on the basis of the content of another, or itself.
malcolmmca at 2007-7-12 10:23:06 > top of Java-index,Java Essentials,Java Programming...
# 2
I have one static fieldprivate static SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd");This field is used by various static methods in this
basti78a at 2007-7-12 10:23:07 > top of Java-index,Java Essentials,Java Programming...
# 3
if you have multiple access on your SimpleDateFormat, you can just synchronize theparse() method in the methods that use the SimpleDateFormat.
suparenoa at 2007-7-12 10:23:07 > top of Java-index,Java Essentials,Java Programming...
# 4
Just make it a local variable.You can make the pattern String static final.
YoGeea at 2007-7-12 10:23:07 > top of Java-index,Java Essentials,Java Programming...
# 5
Ok. But is it still risk to use static classes or static methods/fields in class that are shared with multiple applications ie. in servers shared library?
basti78a at 2007-7-12 10:23:07 > top of Java-index,Java Essentials,Java Programming...
# 6

> Ok. But is it still risk to use static classes or

> static methods/fields in class that are shared with

> multiple applications ie. in servers shared library?

That's a big fat YES.

I suspect that you might benefit from investing a couple of hours in the "concurrency" tutorial

http://java.sun.com/docs/books/tutorial/essential/concurrency/

corlettka at 2007-7-12 10:23:07 > top of Java-index,Java Essentials,Java Programming...
# 7
> Ok. But is it still risk to use static classes or> static methods/fields in class that are shared with> multiple applications ie. in servers shared library?Not if you know what you are doingp.s. only member classes can be declared static
YoGeea at 2007-7-12 10:23:07 > top of Java-index,Java Essentials,Java Programming...