1: public class SA367 extends Activity { 2: public void onCreate(Bundle savedInstanceState) { 3: super.onCreate(savedInstanceState); 4: 5: FileAccessThread fileAccess = new FileAccessThread(); 6: Thread first = new Thread(fileAccess); 7: Thread second = new Thread(fileAccess); 8: Thread third = new Thread(fileAccess); 9: Thread fourth = new Thread(fileAccess); 10: first.start(); 11: second.start(); 12: third.start(); 13: fourth.start(); 14: } 15: } 16: 17: class FileAccessThread implements Runnable { 18: public synchronized void run() { 19: try { 20: File f = new File("Test.txt"); 21: if (f.exists()) { // 만약 파일이 존재하면 파일 내용을 읽음 22: Thread.sleep(100); // 시간이 소요되는 작업을 가정함 23: BufferedReader br = new BufferedReader(new FileReader(f)); 24: System.out.println(br.readLine()); 25: br.close(); // 파일 내용을 모두 읽은 후 삭제 26: f.delete(); 27: } 28: } catch (IOException e) { // 예외처리 29: System.err.println("IOException occured"); 30: } 31: } 32: }