Develop #1

Merged
Meraj merged 2 commits from develop into main 2026-08-01 00:49:46 +00:00
2 changed files with 32 additions and 0 deletions
Showing only changes of commit 85950c58c4 - Show all commits
View File
@@ -0,0 +1,32 @@
package dev.banking.model;
import java.util.concurrent.atomic.AtomicInteger ;
public class bonus {
private static int normalVariable = 0 ;
private static final AtomicInteger atomicVariable = new AtomicInteger(0) ;
public static void main(String[] args) throws InterruptedException{
int numberOfThrad = 10 ;
int incrementsPerThread = 10000 ;
Thread[] threads = new Thread[numberOfThrad] ;
Runnable task = () -> {
for (int i = 0 ; i < incrementsPerThread ; i ++ )
{
normalVariable ++ ;
atomicVariable.incrementAndGet() ;
}
};
for (int i = 0 ; i < numberOfThrad ; i ++)
{
threads[i] = new Thread(task) ;
threads[i].start();
}
for (Thread thread : threads)
{
thread.join();
}
System.out.println("Expected Value (مقدار مورد انتظار): " + (numberOfThrad * incrementsPerThread));
System.out.println("Normal Integer Result (متغیر معمولی): " + normalVariable);
System.out.println("Atomic Integer Result (متغیر اتمیک): " + atomicVariable.get());
}
}