Java Thread start()方法

java.lang.Thread.start() 方法使该线程开始执行时,Java虚拟机调用该线程的run方法。其结果是,两个线程同时运行:在当前线程(其返回从调用start方法)和另一个线程(执行其run方法)。

1 语法

public void start()

2 参数

3 返回值

4 示例 

package com.yiidian;

/**
 * 一点教程网: http://www.yiidian.com
 */
/**
 * java.io.RandomAccessFile.readLong()方法的例子
 */
import java.io.*;

public class Demo {
    public static void main(String[] args) {

        try {
            long l = 536475859696l;

            // create a new RandomAccessFile with filename test
            RandomAccessFile raf = new RandomAccessFile("d:/test.txt", "rw");

            // write something in the file
            raf.writeLong(l);

            // set the file pointer at 0 position
            raf.seek(0);

            // print the long
            System.out.println("" + raf.readLong());

            // set the file pointer at 0 position
            raf.seek(0);

            // write something in the file
            raf.writeLong(4876347485l);

            raf.seek(0);
            // print the long
            System.out.println("" + raf.readLong());

        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}

输出结果为:

thread  = Thread[Admin Thread,5,main]
Calling run() function... 
Inside run()function

热门文章

优秀文章