static « Thread Safe « Java Thread Q&A

Home
Java Thread Q&A
1.concurrency
2.Development
3.Exception
4.Notify
5.Operation
6.Socket
7.State
8.synchronize
9.Thread Safe
10.ThreadPool
Java Thread Q&A » Thread Safe » static 

1. Static method to be accessed by multiple threads, Java    stackoverflow.com

I am using a third party library to do hand evaluation of 7 card poker hands. The method evaluate in this library is declared as public static and I believe it ...

2. Java static and thread safety or what to do    stackoverflow.com

I am extending a library to do some work for me. Here is the code:

public static synchronized  String decompile(String source, int flags,UintMap properties,Map<String,String> namesMap)
    {
   ...

3. static method and thread safety    stackoverflow.com

Is the following code threadsafe ?

    public static Entity getInstance(){
//the constructor below is a default one.
     return new Entity();
    }

4. guava-libraries - Is the Ordering class thread safe?    stackoverflow.com

The guava-libraries have a class Ordering. I'm wondering if it's thread safe. For example, can it be used as a static variable?

public static Ordering<String> BY_LENGTH_ORDERING = new Ordering<String>() ...

5. java:singleton, static variable and thread safety    stackoverflow.com

class MyClass
{
private static MyClass obj;

public static MyClass getInstance()
{
    if(obj==null)
    {
        obj = new MyClass();
    }
 ...

6. How to make a static Calendar thread safe    stackoverflow.com

I'd like to use a Calendar for some static methods and use a static field:

private static Calendar calendar = Calendar.getInstance();
Now I read java.util.Calendar isn't thread safe. How can I make this ...

7. Is static inner class thread safe inside another java class?    stackoverflow.com

For collection of smaller helper utility classes, I have created a general class MyUtils:

// MyUtils.java
public final class MyUtils
{
  public static class Helper1 {};
  public static class Helper2 {};
//...
}
This helper ...

8. Thread safety for static variables    stackoverflow.com

class ABC implements Runnable {
    private static int a;
    private static int b;
    public void run() {
    }
}
I have ...

9. Is static function thread safe ?    bytes.com

You didn't show us the code for that static method; there are no special reasons why or why not a static method would (not) be thread-safe; i.e. the same rules count: ...

10. Static Methods with local variables.. Thread Safe?    coderanch.com

Hi First off let me say that my answer to my own question would be. There's is a synchronization problem, you have to synchronize around the collection someList. Now the problem.. hehe.. I have static methods in a class, these methods have no synchronization but there's a collection defined in the method. This collection used to add a list of 'items' ...

11. Are static methods that don't use class variables safe?    coderanch.com

If I have a static method that only uses internal variables or variables that came as parameters on the function call, this function is thread safe? I mean, these internal function values are stored in the calling thread's stack or other place? Imagine this (useless) method: public static int sum(long first, float second){ int returnValue = (int) first; try{ Thread.sleep(); } ...

12. some question about static methods and Thread safety , please    coderanch.com

In general what makes something unsafe is two threads locking or modifying a shared resource like an object, file, database or partner system. Your method didn't do that, so it's ok for now. You could have a shared resource as a static varible, a parameter, a member variable on a singleton, anything you get from another method, anything you give to ...

13. static method - thread safety    coderanch.com

I've read a lot on threads, but have yet to see an answer for the following. Is a static method thread-safe if: 1.) it's not accessing any static variables, and 2.) it's not modifying objects passed in? I have a utility class for reporting which has static methods that accept a List. I'm wondering if it should be synchronized and why. ...

14. Is static inner class thread safe?    coderanch.com

Thread safety is an issue that gains relevance when you realize that more than one thread could be concurrently performing read/write operations over a particular variable, either static or non-static. Therefore, it does not matter if your class is an static inner class or not. The questions is, is there any possibility that more than one thread is reading/writing its members ...

15. static, instance methods, Thread safe issue    coderanch.com

Hi 1- Instance data accessed only by synchronized instance methods. 2- Static data accessed only by synchronized static methods. You have to respect this rules if you do not want to have a nasty bug. but what if I need to access static data by synchronized instance method or the vise versa, I was told that there is a way to ...

16. Are Static methods Thread safe?    coderanch.com

17. Threadsafe 'static variable'    coderanch.com

Sure you can. One possibility is the one Pho Tek gave: use a final variable. Preferably it should be either a primitive type or a reference to an immutable instance. Another possibility, however, is to let the variable be non-final, and private - and then make sure that every time you access the variable, it is either (a) inside a static ...

18. Marking a variable static final is thread safe    coderanch.com

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - ...

19. Is method parameters passed to static methods thread safe??    coderanch.com

Hi All, I have a doubt regarding method parameters passed to static methods in java. Suppose I have a static method on a object A, say public static String void process( String b, String c, SomeObject X) { } 1.) The Static Method modifies SomeObject X. 2.) The Static Method modifies b and c. 3.) The static Method returns a String ...

20. are static methods not thread safe?    coderanch.com

Its not a question of static versus instance, it is a question of how many Threads and how many objects. In a servlet environment there can be lots of Threads and only one set of static variables and methods. Therefore, if you are going to use static methods you must make them Threadsafe: 1. Using only local variables when the state ...

21. Is static inner class thread safe?    coderanch.com

22. Are Method Parameters passed to static methods Thread Safe??    coderanch.com

Hi All, I have a doubt regarding method parameters passed to static methods in java. Suppose I have a static method on a object A, say public static String void process( String b, String c, SomeObject X) { } 1.) The Static Method modifies SomeObject X. 2.) The Static Method modifies b and c. 3.) The static Method returns a String ...

23. Static methods and thread safety    coderanch.com

Hi, I have a Utility class with all static methods. By definition, static means only one instance.I m working on a multi-threaded application where I m using these static methods to do some work for me. I m making sure that I m not declaring and class level variables and restricting variables to the methods for thread safety. I m also ...

24. Is static inner class thread safe?    coderanch.com

Thread safety is an issue that gains relevance when you realize that more than one thread could be concurrently performing read/write operations over a particular variable, either static or non-static. Therefore, it does not matter if your class is an static inner class or not. The questions is, is there any possibility that more than one thread is reading/writing its members ...

25. Static variable is thread safe?    coderanch.com

yes definitely static variables are not thread safe.. you have to synchronize the block.... still totally correct.But my point of view , why static variable are not thread safe is the smart question. Static variables are resides inside the method area.Method area is shared among all the threads in the particular JVM because of that you have to synchronize the code ...

26. Are static variable and method threadsafe?    coderanch.com

Hi, Static means shared across all the instances of that Class in a JVM. Shared resources are not thread-safe.Hence Static method or variables are not thread safe. If you are talking about declaring constants using static and final keyword then because they are read-only, they are thread safe. You have to synchronize the static method if you want thread safe nature. ...

27. Question about Thread Safety on Static Java methods.    forums.oracle.com

Say that I am calling ArrayType.getPrimitiveArray() from multiple threads, or calling getDimension() from multiple threads. In situations like this, where a static class has static methods which are called by multiple threads to do some simple work, unless it is stated otherwise, does one assume such static methods lack the synchronized keyword and indeed will generate problems if called by multiple ...

28. Is my static method thread safe?    forums.oracle.com

29. Are static methods in Java thread safe?    forums.oracle.com

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.