Skip to content
Advertisement

Tag: multithreading

Adding money from one account to another using multithreading

I have 2 accounts and 2 threads. 1 thread transfers money from 1 account to 2 account, 2 thread transfers money from 2 account to 1 account, if of course there is enough money. I need to realize the deadlock situation and solve the deadlock situation confirming safe transfer. Here is what I have for now: Account.java Main.java TransferThread.java I

Multiple thread failed to execute the nonsynchronized code in java

If Thread1 get the lock and start executing the synchronized block, During the same time,Thread2 is free to execute the non-synchronized part of the code which is IntStream.range(0, 5).forEach(x -> System.out.println(“thread Unsafe Zone,”+name)). Unexpectedly,below is what actually happening while i run code. Explaintation- Suppose,thread1(or thread2) get the lock and execute the synchronized block and then thread2( or thread1) get the

Advertisement