Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class MainThread {
- @SuppressWarnings("deprecation")
- public static void main (String[] args){
- List<Integer> IntList = new ArrayList<Integer>();
- Inputter Input2 = new Inputter((IntList));
- Outputter Output2 = new Outputter((IntList));
- Thread i = new Thread (Input2);
- Thread j = new Thread (Output2);
- try
- {
- i.start();
- Thread.sleep(2);
- j.start();
- Thread.sleep(20);
- i.stop();
- j.stop();
- }
- catch (Exception e)
- {
- }
- System.out.println("végül: " + IntList.size());
- }
- }
- ====================================================================================================
- import java.util.*;
- public class Outputter implements Runnable {
- List<Integer> a;
- Outputter (List<Integer> _a){
- a = _a;
- }
- @Override
- public void run() {
- // TODO Auto-generated method stub
- while(true){
- int ExampleInt = a.get(a.size() - 1);
- System.out.println(ExampleInt);
- a.remove(a.size() - 1);
- Thread.yield();
- }
- }
- }
- ====================================================================================================
- import java.util.*;
- public class Inputter implements Runnable {
- List<Integer> a;
- Inputter (List<Integer> _a){
- a = _a;
- }
- @Override
- public void run() {
- // TODO Auto-generated method stub
- while(true){
- int ExampleInt = a.size()+1;
- a.add(ExampleInt);
- Thread.yield();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement