
多线程
文章平均质量分 56
「已注销」
比较喜欢交流,希望大家关注
展开
-
单线程问题
Java中单线程的写法import java.io.*;public class WithoutThread { static PrintWriter out = new PrintWriter(System.out, true); public static void main(String[] args) { NoThreadPseudoIO pseudo = new...原创 2010-10-14 10:57:17 · 135 阅读 · 0 评论 -
线程学习之Runable接口
class HelloThread implements Runnable { String message; HelloThread( String message ) { this.message = message; } public void run() { int sleeptime = ( int )( Math.random() * 3000 ); ...原创 2010-10-14 11:45:35 · 100 阅读 · 0 评论 -
线程学习之join()
class HelloThread extends Thread { String message; HelloThread( String message ) { this.message = message; } public void run() { int sleeptime = ( int )( Math.random() * 3000 ); ...原创 2010-10-14 11:44:44 · 96 阅读 · 0 评论 -
线程学习
import java.io.*;class Daemon extends Thread { private static final int SIZE = 10;//定义一个静态常量 private Thread[] t = new Thread[SIZE];//定义一个线程数组 public Daemon() {//构造方法 setDaemon(true);//设置一...原创 2010-10-14 11:43:11 · 84 阅读 · 0 评论 -
线程的各种异常信息
import java.io.*;public class ThreadInfo { static PrintWriter out = new PrintWriter(System.out, true); public static void main(String[] args) { Thread[] threads = new Thread[4]; ThreadGr...原创 2010-10-14 11:41:51 · 120 阅读 · 0 评论 -
线程的方法
import java.io.*;public class MethodTest { static PrintWriter out = new PrintWriter(System.out, true);//创建一个打印流 public static void main(String[] args) { FirstThread first = new FirstThread(...原创 2010-10-14 11:40:29 · 85 阅读 · 0 评论 -
线程初步
import java.net.*;import java.io.*; public class RunnableDemo { public static void main(String args[]) { ServerSocket s = null; Socket s1; String sendString = "Hello Net World!";...原创 2010-10-14 11:37:32 · 93 阅读 · 0 评论 -
线程冲突1
class DataObject { int dataItem1; int dataItem2; DataObject() { dataItem1 = 50; dataItem2 =50; } void itemSwap() { int x = (int)( -4.999999+Math.random() * 10); dataItem1 -= x;...原创 2010-10-14 11:34:25 · 112 阅读 · 0 评论 -
线程冲突2
import java.io.*;class DataFile { public DataFile() { try { FileIO.writeOneString( "Hello ","zliner.txt"); }catch( FileIOException e) {} } void fileIO() { try { String str =...原创 2010-10-14 11:15:11 · 99 阅读 · 0 评论 -
同步线程2
class DataObject { int dataItem1; int dataItem2; DataObject() { dataItem1 = 50; dataItem2 = 50; } synchronized void itemSwap() { int x = ( int )( -4.999999 + Math.random() * 10 );...原创 2010-10-14 11:13:45 · 99 阅读 · 0 评论 -
生产者和消费者同步线程
public class HoldIntegerSynchronized { private int sharedInt=-1; private boolean writeable=true; public synchronized void setSharedInt(int val) { while(!writeable) { try {...原创 2010-10-14 11:12:17 · 110 阅读 · 0 评论 -
生产者和消费者的不同步
public class ConsumeInteger extends Thread{ private HoldIntegerUnsynchronized cHold; public ConsumeInteger(HoldIntegerUnsynchronized h) { super("ConsumeInteger "); cHold=h; } ...原创 2010-10-14 11:09:00 · 226 阅读 · 0 评论 -
生产和消费
生产和消费import java.io.*;public class WaitPandC { static int produceSpeed = 200; static int consumeSpeed = 200; public static void main(String[] args) { if(args.length > 0) { produceS...原创 2010-10-14 11:03:09 · 120 阅读 · 0 评论 -
三个并发线程
三个并发线程public class ThreadBasic extends Thread { String message; ThreadBasic (String message) {//类ThreadBasic的构造函数 this.message=message; } public void run() {//实现重定义父类的run方法// ...原创 2010-10-14 11:01:37 · 311 阅读 · 0 评论 -
多线程问题
多线程问题import java.io.*;public class WithThread { static PrintWriter out = new PrintWriter(System.out, true); //创建一个打印流 public static void main(String[] args) { ThreadPseudoIO pseudo = new ...原创 2010-10-14 10:59:56 · 155 阅读 · 0 评论 -
线程优先级
import java.io.*;public class PriorityTest { static int NUM_T = 4; static boolean yield = true; static int[] counter =new int[NUM_T]; public static void main(String[] args) { PrintWrite...原创 2010-10-14 11:46:31 · 93 阅读 · 0 评论