2012년 8월 7일 화요일

안드로이드 쓰레드 7/10

이전에 포스팅했던 future task가 안드로이드에서도 되는지 시험해 보았다.

잘되넹.

Thread, Handle이랑 Excutor랑 이래저래 섞어서 쓰면 좋겠다 싶은데

사실 구조상으로 보면 Futuretask가 AsyncTask랑 같아 보인다.

package com.example.test1;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
    final FutureTask

fTask = new FutureTask

(new MyCallable());

        
    ExecutorService excutor = Executors.newFixedThreadPool(1);
excutor.submit(fTask);
excutor.shutdown();
    }

class MyCallable implements Callable

{

public Object call() throws Exception {
for (;;) {
Log.v("FTASK", "FUTURE TASK");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
    

@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    
}

댓글 없음:

댓글 쓰기

국정원의 댓글 공작을 지탄합니다.

UPBIT is a South Korean company, and people died of suicide cause of coin investment.

 UPBIT is a South Korean company, and people died of suicide cause of coin. The company helps the people who control the market price manipu...