threadsafe « concurrency « 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 » concurrency » threadsafe 

1. Should I always make my java-code thread-safe, or for performance-reasons do it only when needed?    stackoverflow.com

If I create classes, that are used at the moment only in a single thread, should I make them thread-safe, even if I don't need that at the moment? It could ...

2. Is this way of detecting heartbeats threadsafe and consistent?    stackoverflow.com

This question has been discussed in two blog posts (http://dow.ngra.de/2008/10/27/when-systemcurrenttimemillis-is-too-slow/, http://dow.ngra.de/2008/10/28/what-do-we-really-know-about-non-blocking-concurrency-in-java/), but I haven't heard a definitive answer yet. If we have one thread that does this:

public ...

3. Java Transport.send() is it thread-safe?    stackoverflow.com

The method is static, but I cannot find mention of if it is thread-safe or not. I plan on hitting this method with several threads at once and I would ...

4. How can I perform a threadsafe point-in-time snapshot of a key-value map in Java?    stackoverflow.com

In my application, I have a key-value map that serves as a central repository for storing data that is used to return to a defined state after a crash or restart ...

5. Please confirm that this XMPP code is not threadsafe    stackoverflow.com

I'm reading the source code to the Smack api and the the method XMPPConnection#disconnect looks like this:

public void disconnect(Presence unavailablePresence) {
    // If not connected, ignore this request.
 ...

6. This class uses AtomicBooleans. Is it thread safe?    stackoverflow.com

I don't like to lock up my code with synchronized(this), so I'm experimenting with using AtomicBooleans. In the code snippet, XMPPConnectionIF.connect() makes a socket connection to a remote server. Note that ...

7. java array thread-safety    stackoverflow.com

Are there any concurrency problems with one thread reading from one index of an array, while another thread writes to another index of the array, as long as the indices are ...

8. Should I make all my java code threadsafe?    stackoverflow.com

I was reading some of the concurrency patterns in Brian Goetze's Java Concurrency in Practice and got confused over when is the right time to make the code thread ...

9. Not thread safe Object publishing    stackoverflow.com

Reading Java concurrency in practice, section 3.5: Claim is raised that

public Holder holder;
public void initialize() {
     holder = new Holder(42);
}
Besides the obvious thread safely hazard of creating ...

10. How much thread-safety is too much?    stackoverflow.com

I've been reading Java Concurrency in Practice lately – great book. If you think you know how concurrency works, but then most of the time you face the real issues, it ...

11. Is this java code thread-safe?    stackoverflow.com

I am planning to use this schema in my application, but I was not sure whether this is safe. To give a little background, a bunch of servers will compute results of ...

12. is this class thread safe?    stackoverflow.com

consider this class,with no instance variables and only methods which are non-synchronous can we infer from this info that this class in Thread-safe?

public class test{

public void test1{

// do something

}

public void test2{

// ...

13. Is this technically thread safe despite being mutable?    stackoverflow.com

Yes, the private member variable bar should be final right? But actually, in this instance, it is an atomic operation to simply read the value of an int. So is this ...

14. Peterson algorithm in Java?    stackoverflow.com

Is there example implementation of Peterson algorithm for mutual exclusion in Java?

15. How can CopyOnWriteArrayList be thread-safe?    stackoverflow.com

I've taken a look into OpenJDK's sources of CopyOnWriteArrayList and it seems that all write operations are protected by the same lock and read operations are not protected at all. As ...

16. Why ThreadGroup is being criticised?    stackoverflow.com

I'm aware of current practice of using Executors instead of ThreadGroup:

  • generally preferred way to deal with Threads
  • catching exceptions from threads, etc...
However, what are the inherent flaws of ThreadGroup as such (I've ...

17. Writing a thread safe modular counter in Java    stackoverflow.com

Full disclaimer: this is not really a homework, but I tagged it as such because it is mostly a self-learning exercise rather than actually "for work". Let's say I want to write ...

18. There is a rule to find out which objects could possibly have concurrent access in a Java program?    stackoverflow.com

There is a rule to find out, for sure, all objects that could possibly have concurrent access in a Java program? My intention is use such rule, if it exists, to ...

19. Java concurrency question    stackoverflow.com

Possible Duplicate:
Thread safety in Java class
I'm reading Java concurrency in Practice (good book so far), and I've come to an example that puzzles me. The ...

20. Is there any way or tool that I can use to verify whether my API is thread safe in Java?    stackoverflow.com

I make a tool and provide an API for external world, but I am not sure whether it is thread safe. Because users may want t use it in multiple-thread environment. ...

21. Thread safety in java    stackoverflow.com

All, I started learning Java threads in the past few days and have only read about scenarios where even after using synchronizer methods/blocks, the code/class remains vulnerable to concurrency issues. Can anyone ...

22. Approach to a thread safe program    stackoverflow.com

All, What should be the approach to writing a thread safe program. Given a problem statement, my perspective is: 1 > Start of with writing the code for a single ...

23. JAVA: Concurrency control for access to list in java    stackoverflow.com

I have a multi-threaded application that has a centrlaised list that is updated (written to) only by the main thread. I then have several other threads that need to periodically retrieve ...

24. java object serialization - thread safe?    stackoverflow.com

I am writing highly concurrent application, which is extensively modifies objects of MyClass. The class is composed of several fields. My question is how to prevent modifications of particular object during ...

25. In Java Concurrency In Practice by Brian Goetz, why is the Memoizer class not annotated with @ThreadSafe?    stackoverflow.com

Java Concurrency In Practice by Brian Goetz provides an example of a efficient scalable cache for concurrent use. The final version of the example showing the implementation for class Memoizer (pg ...

26. Features for profiling concurrent program behaviour in Java    stackoverflow.com

Nowadays there are some profilers which promise to profile concurrent behavior of program execution in order to understand the threaded execution. I am collection features which would be useful for a Java ...

27. Are non-synchronised static methods thread safe if they don't modify static class variables?    stackoverflow.com

I was wondering if you have a static method that is 'not' synchronised, but does 'not' modify any static variables is it thread-safe? What about if the method creates local variables ...

28. is Java HashSet thread-safe for read only?    stackoverflow.com

If I have an instance of an HashSet after I ran it through Collections.unmodifiableSet(), is it thread-safe? I'm asking this since Set documentation states that it's not, but I'm only performing read ...

29. Is this class Threadsafe?    stackoverflow.com

Hi
Is the class below threadsafe?

class ImmutablePossiblyThreadsafeClass<K, V> {

    private final Map<K, V> map;

    public ImmutablePossiblyThreadsafeClass(final Map<K, V> map) {
       ...

30. java: threadsafe data structure (Queue + Map) for storing pending network requests?    stackoverflow.com

I need to use some kind of data structure to store pending network requests. Ideally I would like a queue which also offers Map access, as the operations are basically as follows:

interface ...

31. Do I have to use a thread-safe Map implementation when only reading from it?    stackoverflow.com

If I do the following.

  • Create a HashMap (in a final field)
  • Populate HashMap
  • Wrap HashMap with unmodifiable wrapper Map
  • Start other threads which will access but not modify the Map
As I understand it the ...

32. Thread-safe implementation of max    stackoverflow.com

I need to implement global object collecting statistics for web server. I have Statistics singleton, which has method addSample(long sample), which subsequently call updateMax. This has to be obviously thread-safe. ...

33. How to define static Arraylist in thread safe environment    stackoverflow.com

How to define static Arraylist in thread safe environment. I have tried synchronized keyword but I heard using Automic classes from java concurrent package is a best solution for static arraylist. ...

34. Thread Confinement    stackoverflow.com

I am reading Java Concurrency in Practice and kind of confused with the thread confinement concept. The book says that

When an object is confined to a thread, such usage ...

35. multi thread safe class    stackoverflow.com

Question: A) Write a thread safe class with methods doA(), doB(), doC(). Each of these methods must report the method name, time of invocation, and calling ...

36. Thread-Safety in a class    stackoverflow.com

Please can you have a look at the following code and advise whether ClassA is thread-safe or not? If it is not thread-safe, could you please advise where it is breaking?

public ...

37. Concurrent access to a utility static method    stackoverflow.com

We have a scenario in which several threads call a static method like the following one:

public static boolean isEmpty(final String s) {
    return s == null || s.length() ...

38. Java - Immutable array thread-safety    stackoverflow.com

I have a question regarding the Java Memory Model. Here is a simple class presenting the problem:

public class ImmutableIntArray {

    private final int[] array;

   ...

39. Different types of thread-safe Sets in Java    stackoverflow.com

There seems to be a lot of different implementations and ways to generate thread-safe Sets in Java. Some examples include 1) CopyOnWriteArraySet 2) Collections.synchronizedSet(Set set) 3) ConcurrentSkipListSet 4)

40. Publishing Non-Thread Safe Object Fields in a Thread-Safe Manner    stackoverflow.com

I've got a problem with Java concurrency. Yes, I looked at questions with almost the exact same title, but they all seemed to be asking subtly different things. Yes, I've read ...

41. java concurrency    stackoverflow.com

i have a list of personId .. There are two api calls to update (add and remove ) from it

public void add(String newPersonName){
    if(personNameIdMap.get(newPersonName) != null){
   ...

42. Concurrent crash using a Vector in Java    stackoverflow.com

I think I'm not understanding correctly what means that a Vector in Java is synchronized. In my code some threads are running instructions that modify my vector, for example calling to ...

43. what is wrong with this thread-safe byte sequence generator?    stackoverflow.com

I need a byte generator that would generate values from Byte.MIN_VALUE to Byte.MAX_VALUE. When it reaches MAX_VALUE, it should start over again from MIN_VALUE. I have written the code using AtomicInteger (see ...

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.