java中创建线程的方法
来源:互联网 发布:政务数据开放流程 编辑:程序博客网 时间:2024/06/15 10:48
There are two ways to create a new thread of execution. One is to declare a class to be a subclass of Thread. This subclass should override the run method of class Thread. An instance of the subclass can then be allocated and started. For example, a thread that computes primes larger than a stated value could be written as follows:
class PrimeThread extends Thread{ long minPrime; PrimeThread(long minPrime){ this.minPrime = minPrime } public void run(){ //compute primse larger than minPrime ... }}
The following code would then create a thread and start it running:
PrimeThread p = new PrimseThread(143);p.start();
The other way to create a thread is to declare a class that implements the Runnable interface.That class then implements the run method. An instance of the class can then be allocated, passed as an argument when creating Thread, and started. The same example in this other style looks like the following:
class PrimeRun implements Runnable{ long minPrime; PrimeRun(long minPrime){ this.minPrime = minPrime; } public void run(){ //compute primie larger than minPrime ... }}
The following code would then create a thread and start it running:
PrimeRun p = new PrimeRun(143);new Thread(p).start();
- java中创建线程的的方法
- java中创建线程的方法
- Java 线程的创建方法
- Java 创建线程的方法
- java 线程创建的方法
- Java线程的创建方法
- Java 创建线程的方法
- java中创建线程的两种方法的区别
- JAVA中创建线程对象的两种方法
- java中创建线程的两种方法及其区别
- Java中创建线程的两种方法
- 在Java中,关于线程的创建,方法及生命周期
- java中线程创建的第二种方法
- JAVA中线程创建的2种方法
- java中创建线程的两种方法及比较
- Java中线程的创建
- java中线程的创建
- java中线程的创建
- POJ 2586--Y2K Accounting Bug
- 编写高质量代码改善Java程序的151个建议--总结摘抄
- JAVA多线程实现的三种方式
- ssm框架数据库取数据在前台分页显示
- Xcode添加main函数输入参数
- java中创建线程的方法
- ABP简单页面
- 关系型数据库工作原理简述
- C++ list用法
- uvalive6886 快速傅里叶变换模板
- 【LibUIDK界面库系列文章】Edit控件在不同操作系统及编译环境下的区别
- 数据结构与算法·实验五
- 关于Servlet编程
- DB数据库的事务特征