Questions tagged [atomicboolean]

29 questions
1
vote
4 answers

Android - Return boolean value from within a Thread

Im trying to return a boolean value from a runnable method within a Thread. I need to know whether a HTTPRequest method succeeded or not. The problem is I know the request is successful but I always get false as the response. public boolean…
Alex
  • 1,982
  • 4
  • 37
  • 70
1
vote
4 answers

Is synchronized volatile boolean equal to atomicBoolean?

Volatile should be used when we are doing only read operation on variable, as value updated by one thread will be visible to the other even if the former thread looses CPU and exits the synchronized block. Is that correct? Atomic primitives will be…
Gaurav Seth
  • 186
  • 3
  • 11
0
votes
2 answers

Atomic Variables Accessed within inner classes

So I am doing a sort here and implementing the Comparator interface using an inner class, exceptionMessage and didJsonParsingFailed are variables declared outside the inner class, now java doesn't allow accessing of local variables using inner…
0
votes
2 answers

Is it necessary to make `AtomicBoolean` also `volatile`?

My understanding: Declaring a variable volatile guarantees the visibility for other threads about writes to that variable. Essentially, every write to volatile variable happens-before subsequent reads. I understand the atomicity of…
Alanpatchi
  • 1,177
  • 10
  • 20
0
votes
2 answers

Get the updated value first in AtomicBoolean

getAndSet returns the "previous" value then set the updated value, I want the "reverse" behavior, to return the updated value and then set it in the AtomicBoolean object. just like when you do if(bolVal = otherBolVal) the assignment here precedes…
Alireza Jamali
  • 302
  • 2
  • 6
  • 17
0
votes
1 answer

Synchronization with volatile 'status flag' boolean?

I've read about the 'status flag' pattern for the volatile usage. It says that I can use the volatile without any sync if the status flag doesn't depend on any other state. It will guarantee the visibility of the flag for other threads. Moreover,…
androberz
  • 744
  • 10
  • 25
0
votes
0 answers

How to test atomicboolean in method

I want to test my method for thread-safety. For that I am using an atomicboolean. If it is true, then an exception is thrown. Now i want to test this function. What is the best way to test this function?? public void startProcess() { …
trap
  • 2,550
  • 7
  • 21
  • 42
0
votes
0 answers

Where does the unsafe variable been set

When studying the jdk source code (jdk 1.8.0_111), i found a piece of strange code as follow: public class AtmicBoolean implements Serializable { private static final long serialVersionUID = 4654671469794556979L; private static final Unsafe…
Sampson
  • 9
  • 1
0
votes
4 answers

What is the hashCode of an AtomicBoolean?

I couldn't find any information in the official docs. I know that Boolean.hashCode(boolean b) returns the two primes 1231 and 1237 for true and false. I am hoping for a similar implementation in AtomicBoolean. But in the decompiled class file it…
jcfrei
  • 1,819
  • 4
  • 19
  • 35
0
votes
1 answer

Shared Linked List in Scala

I have a number of worker actors and a list of tasks (a linked list) which is sent to the workers by a master actor. Each element of the linked list has a Boolean flag that specifies whether the element is taken by a worker yet or not. If not, a…
A.G
  • 37
  • 3
0
votes
1 answer

Threads, atomic boolean, synchronized design considerations for a method that has to wait for a result

My code is starting to get a bit hard to debug which leads me to believe that my design choices are not ideal. I am a novice Android programming and would love some help with streamlining the design for optimum operation. Intro I am writing an…
Brandon Fannin
  • 33
  • 1
  • 10
0
votes
1 answer

multithreading problems with atomisboolean

while trying to "develop" a code to drive a robot using an android device, I've been stranded on a stupid issue and after looking to solve it for weeks, I will finally ask you for help. I'm totally new to android and also to java. I'm basically…
0
votes
0 answers

How to stop a screen orientation change from resetting state in my application

When my Thread starts, I set an AtomicBoolean to true. At the end, I reset it to false in the associated Handler. When I change the screen orientation BEFORE the end of the Thread: onSaveInstanceState() prints that this bool is TRUE onPause()…
Anduriel
  • 93
  • 2
  • 10
-5
votes
1 answer

Why does Class AtomicBoolean be initialized not true but false by default constractor?

java source code: static { try { valueOffset = unsafe.objectFieldOffset (AtomicBoolean.class.getDeclaredField("value")); } catch (Exception ex) { throw new Error(ex); } } default constructor do nothing: public AtomicBoolean()…
Flory Li
  • 167
  • 7
1
2