Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pokusaj1;
- public class pokusaj1 {
- public static Thread t1;
- public static Thread t2;
- public static volatile boolean flag1 = false;
- public static volatile boolean flag2 = false;
- public static void createThreads(){
- Runnable proces1 = new Runnable() {
- @Override
- public void run() {
- while(true){
- flag1 = true;
- while (flag2 == true);
- System.out.println("Proces1");
- flag1 = false;
- }
- }
- };
- Runnable proces2 = new Runnable() {
- @Override
- public void run() {
- while(true){
- flag2 = true;
- while(flag1 == true);
- System.out.println("Proces2");
- flag2 = false;
- }
- }
- };
- t1 = new Thread(proces1);
- t2 = new Thread(proces2);
- t1.start(); t2.start();
- }
- public static void main(String[] args){
- createThreads();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement