All pastes #166533 Raw Edit

freeone3000

public java v1 · immutable
·published 2006-09-11 00:04 UTC
rendered paste body
import java.io.*;import java.nio.*;import java.nio.channels.*;public class ThreadTest extends Thread {	private static int num = 0;	private FileChannel fc;	private ThreadTest(FileChannel fc) {		num++;		this.fc = fc;	}	public void start() {		byte[] b;		ByteBuffer bb;		while(true) {			try {				b = new StringBuilder("Thread number: ").append(Integer.toString(num)).toString().getBytes();				bb = ByteBuffer.allocate(b.length);				bb.put(b);				fc.write(bb);			} catch(IOException ioe) {				ioe.printStackTrace();			}		}	}	public static void main(String[] args) {		FileOutputStream fo = null;		try {			File f = new File("test.txt");			f.createNewFile(); //Won't do anything if it doesn't exist.			fo = new FileOutputStream(f);			FileChannel fc = fo.getChannel();			for(int i=0; i<Integer.MAX_VALUE; i++) {				System.out.println(i);				new ThreadTest(fc).start();			}		} catch(IOException ioe) {			ioe.printStackTrace();		} finally {			try {				fo.close();			} catch(IOException ioe) {				ioe.printStackTrace();			}		}	}}