No, you should be using something like java.util.concurrent.atomic.AtomicInteger
. Look at its getAndIncrement()
method.
More Related Contents:
- How to stop a java thread gracefully?
- Handling exceptions from Java ExecutorService tasks
- Swing animation running extremely slow
- java.lang.OutOfMemoryError: Java heap space
- How to synchronize a static variable among threads running different instances of a class in Java?
- Are static variables shared between threads?
- Why should wait() always be called inside a loop
- Java double checked locking
- Is it safe to get values from a java.util.HashMap from multiple threads (no modification)?
- Java increment and assignment operator [duplicate]
- Distinguishing between Java threads and OS threads?
- Javafx: Difference between javafx.concurent and Platform.runLater?
- How are Threads allocated to handle Servlet request?
- How can the wait() and notify() methods be called on Objects that are not threads?
- Java volatile modifier and synchronized blocks
- How to make another thread sleep in Java
- Setting priority to Java’s threads
- How do I properly do a background thread when using Spring Data and Hibernate?
- Java – creating a new thread
- Java Multithreading concept and join() method
- Concept behind putting wait(),notify() methods in Object class [duplicate]
- Is it possible to force an existing Java application to use no more than x cores?
- Handling Exceptions for ThreadPoolExecutor
- Java Synchronization [closed]
- Why should Java ThreadLocal variables be static
- Communicating between two threads
- Is there a good way to forcefully stop a Java thread?
- When may we need to use runOnUiThread in android application?
- How to set up multi-threading in Spring Batch?
- how to override thread.start() method in java?