336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
package com.ygygood.sample_code;
import java.util.ArrayList;
import java.util.List;
public class ThreadTest {
static public List<Integer> arrList;
public ThreadTest() {
arrList = new ArrayList<Integer>();
}
public void start() {
Runnable putWorker = new PutWorker();
Runnable getWorker = new GetWorker();
Thread pThread = new Thread(putWorker);
Thread gThread = new Thread(getWorker);
pThread.start();
gThread.start();
}
public static void main(String[] args) {
new ThreadTest().start();
}
}
class PutWorker implements Runnable{
public void run() {
// TODO Auto-generated method stub
for(int i=1; i<=100; i++) {
try {
Thread.sleep(100);
ThreadTest.arrList.add(i);
System.out.println("PutWoker:"+i);
}
catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
class GetWorker implements Runnable{
public void run() {
// TODO Auto-generated method stub
while(true) {
try {
Thread.sleep(100);
}
catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("size of list:"+ThreadTest.arrList.size());
if(ThreadTest.arrList.size() != 0) {
System.out.println("GetWorker:"+ThreadTest.arrList.get(0));
ThreadTest.arrList.remove(0);
}
}
}
}
'IT > Java' 카테고리의 다른 글
자바 int -> string format (1) | 2021.06.09 |
---|---|
GSON (0) | 2021.06.09 |
Java 현재 날짜 및 조작 (0) | 2021.06.09 |
jetty server (0) | 2021.06.07 |
자바 ArrayList<Object> 정렬 (0) | 2020.09.23 |