added ex S3
This commit is contained in:
32
src/exercises/ex_s3/TestingAtomicLong.java
Normal file
32
src/exercises/ex_s3/TestingAtomicLong.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package exercises.ex_s3;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TestingAtomicLong {
|
||||
public static String[] names = {
|
||||
"Alice", "Bob", "Charlie", "Derek", "Emily",
|
||||
"Fionna", "Greg", "Harry", "Isabella", "Julia"
|
||||
};
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
List<AbstractTweet> tweets = new ArrayList<>();
|
||||
AbstractTweet tweet1 = new Tweet("Alice", "Java is cool !");
|
||||
AbstractTweet tweet2 = new AtomicTweet("Bob", "ISC is the best !");
|
||||
tweets.add(tweet1);
|
||||
tweets.add(tweet2);
|
||||
|
||||
Thread[] users = new Thread[10];
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
users[i] = new Thread(new User(names[i], tweets));
|
||||
users[i].start();
|
||||
}
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
users[i].join();
|
||||
}
|
||||
|
||||
System.out.println(tweet1);
|
||||
System.out.println(tweet2);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user