'개발 > 삽질' 카테고리의 다른 글
vmware에 osx를 설치해 보다 (3) | 2007.04.25 |
---|---|
CyChat.java (0) | 2006.08.01 |
cychat IRC로 접속하기 (0) | 2006.08.01 |
-ㅁ- 블로그 설정완료 (0) | 2006.07.05 |
SIC OPTABLE (0) | 2006.04.21 |
vmware에 osx를 설치해 보다 (3) | 2007.04.25 |
---|---|
CyChat.java (0) | 2006.08.01 |
cychat IRC로 접속하기 (0) | 2006.08.01 |
-ㅁ- 블로그 설정완료 (0) | 2006.07.05 |
SIC OPTABLE (0) | 2006.04.21 |
재미있는??? (1) | 2006.10.09 |
---|---|
허접한 마우스 막기 (0) | 2005.12.23 |
시간 동기화 프로그램입니다.
한국표준과학연구원 표준시 서버와 동기화합니다. [time.kriss.re.kr]http://krissol.kriss.re.kr/time/UTCk3.html
1. cmd>net time /setsntp:time.nuri.net
2. cmd> net stop "windows time" or net stop w32time
3. cmd> net start "windows time" or net start w32time
윈도우에서 .(dot)으로 시작되는 파일들... 버그인가?? (4) | 2007.11.14 |
---|---|
윈도우 재설치 (0) | 2007.08.18 |
administrator(관리자) 계정 암호를 잃어버렸을때. (0) | 2007.03.16 |
특정사이트가 표시되지 않을때 해결방법 (0) | 2006.07.14 |
테스트용으로 만들어본 DFA (3) | 2006.10.14 |
---|---|
Genealogy of Common Languages (2) | 2006.08.02 |
msnbot - mysql db와 연동 (0) | 2006.07.06 |
시내버스노선검색기능구현준비작업 (0) | 2006.01.04 |
eclipse 에서 autoftp플러그인사용 (0) | 2005.12.22 |
Java: OS 알아내기 (1) | 2006.07.06 |
---|---|
java + mysql (0) | 2006.07.06 |
Thread Test (0) | 2006.01.05 |
java : equals() method overriding (0) | 2006.01.01 |
HTMLtest (0) | 2005.12.24 |
[CODE type="java"]
/** 쓰레드 연습 **/
class Data{
[tab]
[tab]private String data;
[tab]private boolean is_saved = false;
[tab]
[tab]public synchronized void setData(String arg){
[tab][tab]
[tab][tab] try{
[tab][tab][tab]
[tab][tab][tab]
[tab][tab][tab] if(is_saved){
[tab][tab][tab][tab] wait();
[tab][tab][tab] }
[tab][tab] }
[tab][tab] catch (Exception e) {
[tab][tab][tab] System.out.println("SET error");
[tab][tab] }
[tab][tab]
[tab][tab] data = arg;
[tab][tab] is_saved = true;
[tab][tab] notify();
[tab][tab]
[tab]}
[tab]public synchronized String getData(){
[tab][tab]
[tab][tab] try{
[tab][tab][tab] if(!is_saved)
[tab][tab][tab][tab] wait();
[tab][tab][tab]
[tab][tab] }
[tab][tab] catch (Exception e) {
[tab][tab][tab] System.out.println("GET error");
[tab][tab] }
[tab][tab]
[tab][tab] String r = data;
[tab][tab] data = "";
[tab][tab] is_saved =false;
[tab][tab] notify();
[tab][tab] return r;
[tab]}
[tab]
[tab]
[tab]public boolean is_saved(){
[tab][tab] return is_saved;[tab][tab]
[tab]}
[tab]
}
class Producer extends Thread{
[tab]Data s;
[tab]Producer(String msg, Data ss){
[tab][tab] s=ss;
[tab][tab] System.out.println(msg);[tab][tab]
[tab]}
[tab]public void run(){
[tab][tab] int i=0;
[tab][tab] while(i<10){
[tab][tab][tab] try{
[tab][tab][tab] sleep((long)(Math.random()*1000));
[tab][tab][tab] }
[tab][tab][tab] catch (Exception e) {
[tab][tab][tab][tab] // TODO: handle exception
[tab][tab][tab] }
[tab][tab][tab]
[tab][tab][tab] System.out.println( "producer is running : " +i);
[tab][tab][tab] s.setData("DATA ("+i+"): " + produce());
[tab][tab][tab][tab] i++;
[tab][tab]
[tab][tab] }//end while
[tab]}//end run
[tab]
[tab]private String produce(){
[tab][tab] int r ;
[tab][tab] r =(int)( Math.random()*10);
[tab][tab] return "" + r;
[tab]}
[tab]
}
class Consumer extends Thread{
[tab]Data s;[tab]
[tab]
[tab]Consumer(String msg,Data ss){
[tab][tab] s = ss;
[tab]
[tab][tab] System.out.println(msg);
[tab]}
[tab]
[tab]public void run(){
[tab][tab] int i=0;
[tab][tab] String data="";
[tab][tab] while(i<10){
[tab][tab][tab] try{
[tab][tab][tab][tab] sleep((long)(Math.random()*1000));
[tab][tab][tab][tab] }
[tab][tab][tab][tab] catch (Exception e) {
[tab][tab][tab][tab][tab] // TODO: handle exception
[tab][tab][tab][tab] }
[tab][tab][tab][tab]
[tab][tab][tab] System.out.println( "consumer is running : " + i);
[tab][tab][tab] data =s.getData();
[tab][tab][tab] System.out.println(">> " + data);
[tab][tab][tab] i++;
[tab][tab][tab]
[tab][tab] }//end while
[tab]}//end run[tab]
}
class Ttest{
[tab]public static void main(String args[])
[tab]{
[tab][tab] Data data = new Data();
[tab][tab] Producer t1 = new Producer("P thread is ready", data);
[tab][tab] Consumer c1 = new Consumer("C thread is ready", data);
[tab][tab]
[tab][tab]
[tab][tab] t1.start();
[tab][tab] c1.start();
[tab][tab]
[tab][tab]
[tab][tab]
[tab][tab][tab][tab]
[tab]}[tab][tab]
}
/**
class Data{
[tab]
[tab]private String data;
[tab]private boolean is_saved = false;
[tab]
[tab]public void setData(String arg){
[tab][tab] data = arg;
[tab][tab] is_saved = true;
[tab]}
[tab]public String getData(){
[tab][tab] String r = data;
[tab][tab] data = "";
[tab][tab] is_saved =false;
[tab][tab] return r;
[tab]}
[tab]
[tab]
[tab]public boolean is_saved(){
[tab][tab] return is_saved;[tab][tab]
[tab]}
[tab]
}
class Producer extends Thread{
[tab]Data s;
[tab]Producer(String msg, Data ss){
[tab][tab] s=ss;
[tab][tab] System.out.println(msg);[tab][tab]
[tab]}
[tab]public void run(){
[tab][tab] int i=0;
[tab][tab] try{
[tab][tab][tab] while(i<10){
[tab][tab][tab][tab]
[tab][tab][tab][tab] System.out.println( "producer is running : " +i);
[tab][tab][tab][tab] if(s.is_saved()){
[tab][tab][tab][tab][tab] yield();
[tab][tab][tab][tab] }
[tab][tab][tab][tab] else{
[tab][tab][tab][tab][tab] s.setData("DATA ("+i+"): " + produce());
[tab][tab][tab][tab][tab] i++;
[tab][tab][tab][tab] }
[tab][tab][tab][tab]
[tab][tab][tab] }//end while
[tab][tab] }
[tab][tab] catch (Exception e) {
[tab][tab][tab] System.out.println(e);
[tab][tab][tab] // TODO: handle exception
[tab][tab] }
[tab]}//end run
[tab]
[tab]private String produce(){
[tab][tab] int r ;
[tab][tab] r =(int)( Math.random()*10);
[tab][tab] return "" + r;
[tab]}
[tab]
}
class Consumer extends Thread{
[tab]Data s;[tab]
[tab]
[tab]Consumer(String msg,Data ss){
[tab][tab] s = ss;
[tab]
[tab][tab] System.out.println(msg);
[tab]}
[tab]
[tab]public void run(){
[tab][tab] int i=0;
[tab][tab] String data="";
[tab][tab] try{
[tab][tab][tab] while(i<10){
[tab][tab][tab][tab] System.out.println( "consumer is running : " + i);
[tab][tab][tab][tab] if(s.is_saved()){
[tab][tab][tab][tab][tab][tab] data =s.getData();
[tab][tab][tab][tab][tab][tab] System.out.println(">> " + data);
[tab][tab][tab][tab][tab][tab] //notifyAll();
[tab][tab][tab][tab][tab][tab] i++;
[tab][tab][tab][tab] }
[tab][tab][tab][tab] else{
[tab][tab][tab][tab][tab] yield();
[tab][tab][tab][tab][tab] yield();
[tab][tab][tab][tab][tab]
[tab][tab][tab][tab][tab] //this.wait();
[tab][tab][tab][tab][tab] //this.suspend();
[tab][tab][tab][tab] }
[tab][tab][tab][tab]
[tab][tab][tab] }//end while
[tab][tab] }
[tab][tab] catch (Exception e) {
[tab][tab][tab] System.out.println(e);
[tab][tab][tab] // TODO: handle exception
[tab][tab] }
[tab]}//end run[tab]
}
class Ttest{
[tab]public static void main(String args[])
[tab]{
[tab][tab] Data data = new Data();
[tab][tab] Producer t1 = new Producer("P thread is ready", data);
[tab][tab] Consumer c1 = new Consumer("C thread is ready", data);
[tab][tab]
[tab][tab]
[tab][tab] t1.start();
[tab][tab] c1.start();
[tab][tab]
[tab][tab]
[tab][tab]
[tab][tab][tab][tab]
[tab]}[tab][tab]
}
**/
[/HTML][/CODE]
java + mysql (0) | 2006.07.06 |
---|---|
gaim에서 sempeebot (0) | 2006.01.14 |
java : equals() method overriding (0) | 2006.01.01 |
HTMLtest (0) | 2005.12.24 |
jmsnm lib cvs server (0) | 2005.12.19 |
테스트용으로 만들어본 DFA (3) | 2006.10.14 |
---|---|
Genealogy of Common Languages (2) | 2006.08.02 |
msnbot - mysql db와 연동 (0) | 2006.07.06 |
bot 추가 기능 구상 (0) | 2006.02.14 |
eclipse 에서 autoftp플러그인사용 (0) | 2005.12.22 |
gaim에서 sempeebot (0) | 2006.01.14 |
---|---|
Thread Test (0) | 2006.01.05 |
HTMLtest (0) | 2005.12.24 |
jmsnm lib cvs server (0) | 2005.12.19 |
java msn bot project start (0) | 2005.12.18 |
gaim에서 sempeebot (0) | 2006.01.14 |
---|---|
Thread Test (0) | 2006.01.05 |
java : equals() method overriding (0) | 2006.01.01 |
jmsnm lib cvs server (0) | 2005.12.19 |
java msn bot project start (0) | 2005.12.18 |
재미있는??? (1) | 2006.10.09 |
---|---|
zboard encoding 바꾸기 (0) | 2006.03.04 |