Thread Safe « 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 » Thread Safe 

1. Any satisfactory approaches to unit testing thread safety in Java?    stackoverflow.com

I am looking at improving a package that I believe not to be threadsafe when its input is shared between multiple worker threads. According to TDD principles, I should write ...

2. OGNL thread safety    stackoverflow.com

I'm going to reuse OGNL library out of Struts2 scope. I have rather large set of formulas, that is why I would like to precompile all of them:

Ognl.parseExpression(expressionString);
But I'm not sure ...

3. httpurlconnection thread safety    stackoverflow.com

Is HttpUrlConnection thread safe? I.e. if I have an HttpConnection instance connected to a server and this instance is used by different threads (e.g.try to send a POST concurrently) how ...

4. ScheduledThreadPoolExecutor Thread Safety    stackoverflow.com

Are ThreadPoolExecutor and ScheduledThreadPoolExecutor thread-safe?? Now, I have a scenario as under:

  • 5 ThreadPoolExecutor(s)
  • exec1 (which executes JobA (Job of Level A) : parallelism of 4-5 jobs max),
  • exec2 (which executes JobB (made from ...

5. Thread safety in Java class    stackoverflow.com

Why is this java class not Thread safe.

class TestClass
{  private int x;

   int get(){return x;}
   void set(int x){this.x = x;}  
}
I read that keyword 'synchronized' ...

6. Resources for learning memory model and Thread safety in java    stackoverflow.com

I have been searching for resources to understand thread safety in java and came across this. Is there any popular/comprehensive resource or books that explains thread safety in a ...

7. Using compareAndSet for Thread safety    stackoverflow.com

How is the following demo code thread-safe? We are ensuring whether the value is not modified in CAS instruction and then doing an increment on int. Doesn't return v + 1; ...

8. When do you have to worry about thread safety?    stackoverflow.com

What are some situations where you need to worry about whether a static method is thread safe? For example, if I have static utility function that doesn't touch any static class level ...

9. Java: naming conventions for thread safety?    stackoverflow.com

Imagine I have this class:

class Notifier {
    public Listener listener;

    public void notify() {
        if (listener != null) ...

10. Java thread safety of list    stackoverflow.com

I have a List, which is to be used either in thread-safe context or in a non thread-safe one. Which one will it be, is impossible to determine in advance. In such ...

11. Safe publication: does first time passing of Object reference to another thread require safe publication idioms?    stackoverflow.com

I have a class C with definition as given below:

public Class C implements Runnable
{
    private B ref;
    public C(B bobj)
    {
  ...

12. How to execute a thread safety method on the server side in Java?    stackoverflow.com

I have a client application that communicates with a server. In this application the clients can send requests to the server in order to reserve hotel rooms. The problems is that, if ...

13. Thread Safety of files    stackoverflow.com

I have many applications writing to my file in concurrent in java.I want to make this operation concurrent and also want my file to preserve order.I have Thread 1 writing from ...

14. Can someone explain Thread Safety in layman terms?    stackoverflow.com

Despite me reading wikipedia and such, I still don't really understand what Thread Safety means in a programming sense. Is anyone able to give some Java examples in layman terms? Such ...

16. atomicity & thread safety with primitives    coderanch.com

I understood that only long and double needed explicit sychronization as they are 64 bit in size considering many of the processors are 32 bit. If this understanding is correct consider this: Class ThreadSafety { private int i; public int getInt() { return i; } public void setInt(int var) { i = var; } // (1) //public sychronized void setInt(int var) ...

17. Thread Atomicity and Safety    coderanch.com

Let's assume there are shared objects or primitives among a group of threads, and there are no synchronization methods nor are these objects known thread-safe classes such as Hashtable/Vector. How much atomicity is there for simple objects or primitives under these circumstances? What kind of thread safey conflicts for reading/writing data can you expect and under what conditions? Ok that's a ...

18. Confused about thread safety    coderanch.com

I think I'm misunderstanding something very fundamental about method synchronization and thread safety. Here's some example code from Java's String class about what I'm not grasping. Notice that the toUpperCase method is public and NOT synchronized. It calls the upperCaseIndex method which is also not synchronized but IS static. So, this doesn't seem safe to me. Meaning, couldn't two instances of ...

19. Thread safety of this example.    coderanch.com

public class ThreadTest { //Note that I have no class level variables protected void method1(SomeObject myObject) { SomeSubObject subObject = myObject.getSubObject(); String theReturn = method2(subObject); myObject.setReturn(theReturn); } public static String method2(SubObject subObject) { StringBuffer buf = new StringBuffer(64); synchronized (buf) // IS THIS NEEDED? { buf.append((subObject.getValue1()) .append(subObject.getValue2()) .append(' ') .append(subObject.getValue3())); } return buf.toString(); } }

21. Thread Safety in a Single Instance of a class    coderanch.com

Hi, i have to redesign a class, say X, in such a way that i manage multiple threads accessing a single instance of the class, we cannot create multiple instances of X. The class looks like this: Class X{ boolean isACalled=false; boolean isInitCalled=false; boolean isBCalled=false; A(){ isACalled=true; } Init(){ if(!isACalled) A(); B(); C(); isInitCalled=true; } B(){ if(!isACalled) A(); isBCalled=true; } C(){ ...

22. Reentrant vs Thread Safety    coderanch.com

There seems to be an assumption in this thread that "reentrant" is a term restricted to the topic of threading. It isn't. Java locks are reentrant. That means that a thread that already holds the lock can safely enter another block of code, synchronised using the same lock. Some other platforms do not have reentrant locks, and you somehow have to ...

23. About threads safety    coderanch.com

hi all, this afternoon, my techer give us a piece of code to ask how to make the code threads safety. Code: public class Test { private int b; public void foo(){ int current =b; b= current +1; } public void go(){ for (int i=0;i<5;i++){ new Thread(){ public void run(){ foo(); System.out.println(b+","); } }.start(); } } public static void main(String[] args){ ...

24. FileChannel and thread safety    coderanch.com

FileChannel and thread safety (I/O and Streams forum at JavaRanch) A friendly place for programming greenhorns! Register / Login Java Forums Java I/O and Streams FileChannel and thread safety Post by: S Bala, Ranch Hand on Jul 15, 2003 13:49:00 This is Jim Y here, intruding on S Bala's original post. These posts were originally in another thread here, ...

25. Concern about Thread safety    coderanch.com

Hi guys, I'm not sure about the thread safety of one of my classes. Here is some code. import java.util.ArrayList; import java.util.List; public class Main { public static void main(String[] args) { ThreadSafety threadSafety = ThreadSafety.getInstance(); threadSafety.doItSafe(); } } class ThreadSafety { private static ThreadSafety threadSafety; private IMustBeSafe iMustBeSafe; private ThreadSafety() { iMustBeSafe = new IMustBeSafe(); } public static ThreadSafety getInstance() ...

26. thread safety ?    coderanch.com

It is NOT thread safe. You are synchronizing an instance method that modifies a static variable. Each instance of the class Test has its own lock ensuring that no 2 threads will access the doit() method on the same single instance of Test simultaneously. But nothing stops somebody from constructing multiple instances of Test and starting all of them up. In ...

27. simulation of trading application, thread safety issues ?    coderanch.com

I am learning Thread, so I write an application to test my understanding. Here is a simulation of trading application. The vendor, like Bloomberg, send out the latest market data of a security. My application receives it and save it into queue. And threads will process it one by one. After this action, it will save the updated security into another ...

28. is thread.sleep safe?    coderanch.com

29. How is this a safe publication?    coderanch.com

Hi, I am going through the following url Java theory and practice - IBM Under the section, What do you mean by "publish"? , the following code is written public class Safe { private Object me; private Set set = new HashSet(); private Thread thread; public Safe() { // Safe because "me" is not visible from any other thread me = ...

30. Thread safety?    java-forums.org

31. Thread safety! Is this the right way?    forums.oracle.com

Threading looks fine too me... the connection is created on a background thread, but (critically) all GUI updates are performed on the EDT, even if there's an exception. Well done. My only comment is... why is your GUI creating a database connection at all? Ideally the controler would get the DAO (which would connect itself) and inject it (the connected DAO) ...

32. Thread safety    forums.oracle.com

33. Thread safety How-to ??    forums.oracle.com

I have an inner class instantiated twice in my main application. Each instantiation instantiates the same extension of class Thread. Next a different extension of Thread is instantiated from the main application, and sleeping and looking at a variable in each of the two mentioned inner classes, waits for data to be ready then does its thing. Im calling methods of ...

34. Thread Safety    forums.oracle.com

As per the description of volatile:- "The Java programming language provides a second mechanism, volatile fields, that is more convenient than locking for some purposes. A field may be declared volatile, in which case the Java memory model (17) *ensures that all threads see a consistent value for the vari*able." In which case my guess is that Thread 2's getFoo method ...

35. thread safety of java.io.File.    forums.oracle.com

Encountered a strange problem when working on a small piece code that is supposed to tally up the number of files, sub-directories and total sizes for a given list of directories using java.io.File. Because the list could be long, the initial version of the code used multiple threads, where each thread responsible for the accounting of a directory off the list. ...

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.