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 ... |
|
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 ... |
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 ... |
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.
...
|
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 ... |
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 ... |
|
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 ... |
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 ... |
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 ... |
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 ... |
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{
// ...
|
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 ... |
Is there example implementation of Peterson algorithm for mutual exclusion in Java?
|
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 ... |
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 ... |
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 ... |
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 ... |
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 ... |
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. ... |
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 ... |
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 ... |
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 ... |
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 ... |
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 ... |
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 ... |
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 ... |
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 ... |
Hi
Is the class below threadsafe?
class ImmutablePossiblyThreadsafeClass<K, V> {
private final Map<K, V> map;
public ImmutablePossiblyThreadsafeClass(final Map<K, V> map) {
...
|
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 ...
|
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 ... |
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. ... |
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. ... |
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 ... |
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 ... |
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 ...
|
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() ...
|
I have a question regarding the Java Memory Model. Here is a simple class presenting the problem:
public class ImmutableIntArray {
private final int[] array;
...
|
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) |
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 ... |
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){
...
|
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 ... |
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 ... |