Java 多线程 线程间通信-等待唤醒机制

线程间通讯:其实就是多个线程在操作同一个资源,但是操作的动作不同。

class Res
{
    String name;
    String sex;
}
class Input implements Runnable
{
    private Res r;
    private int x = 0;
    Input(Res r)
    {
        this.r = r;
    }
    public void run()
    {
        while (true)
        {
            synchronized (r)
            {
                if (x==0)
                {
                    r.name = "mike";
                    r.sex = "man";
                }
                else
                {
                    r.name = "丽丽";
                    r.sex = "女女女女女女";
                }
                x = (x+1)%2;
            }
        }
    }
}
class Output implements Runnable
{
    private Res r;
    Output(Res r)
    {
        this.r = r;
    }
    public void run()
    {
        while (true)
        {
            synchronized (r)
            {
                System.out.println(r.name+"....."+r.sex);
            }
        }
    }
}
public class InputOutputDemo {
    public static void main(String[] args) {
         Res r = new Res();
         Input in = new Input(r);
         Output out = new Output(r);

         Thread t1 = new Thread(in);
         Thread t2 = new Thread(out);

         t1.start();
         t2.start();
    }
}
//输出正常
mike.....man
mike.....man
mike.....man
丽丽.....女女女女女女
丽丽.....女女女女女女
丽丽.....女女女女女女

wait();notify();notifyAll();都使用在同步中,因为要对持有监视器(锁)的线程操作。所以要使用在同步中,因为只有同步才具有锁。

为什么这些操作线程的方法要定义object类中呢?
因为这些方法在操作同步中线程时,都必须要标识他们所操作线程持有的锁,只有同一个锁上的被等待线程,可以被同一个锁上notify唤醒。不可以对不同锁中的线程进行唤醒。
也就是说,等待和唤醒必须是同一个锁。
而锁可以是任意对象,所以可以被任意对象调用的方法定义Object类中。

class Res
{
    String name;
    String sex;
    boolean flag = false;
}
class Input implements Runnable
{
    private Res r;
    private int x = 0;
    Input(Res r)
    {
        this.r = r;
    }
    public void run()
    {
        while (true)
        {
            synchronized (r)
            {
                if (r.flag)
                    try { r.wait(); }catch (InterruptedException e){}
                if (x==0)
                {
                    r.name = "mike";
                    r.sex = "man";
                }
                else
                {
                    r.name = "丽丽";
                    r.sex = "女女女女女女";
                }
                x = (x+1)%2;
                r.flag = true;
                r.notify();
            }
        }
    }
}
class Output implements Runnable
{
    private Res r;
    Output(Res r)
    {
        this.r = r;
    }
    public void run()
    {
        while (true)
        {
            synchronized (r)
            {
                if (!r.flag)
                    try { r.wait(); }catch (InterruptedException e){}
                System.out.println(r.name+"....."+r.sex);
                r.flag = false;
                r.notify();
            }
        }
    }
}
public class InputOutputDemo {
    public static void main(String[] args) {
         Res r = new Res();
         Input in = new Input(r);
         Output out = new Output(r);

         Thread t1 = new Thread(in);
         Thread t2 = new Thread(out);

         t1.start();
         t2.start();
    }
}
//输出
mike.....man
丽丽.....女女女女女女
mike.....man
丽丽.....女女女女女女
mike.....man
丽丽.....女女女女女女
mike.....man
丽丽.....女女女女女女
mike.....man
丽丽.....女女女女女女

优化代码为同步函数形式

class Res0 {
    private String name;
    private String sex;
    private boolean flag = false;

    public synchronized void set(String name, String sex) {
        if (flag)
            try { this.wait(); } catch (InterruptedException e) { }
        this.name = name;
        this.sex = sex;
        flag = true;
        this.notify();
    }

    public synchronized void out() {
        if (!flag)
            try { this.wait(); } catch (InterruptedException e) {}
        System.out.println(name + "....." + sex);
        flag = false;
        this.notify();
    }
}

class Input0 implements Runnable {
    private Res0 r;
    private int x = 0;

    Input0(Res0 r) {
        this.r = r;
    }

    public void run() {
        while (true) {
            if (x == 0) {
                r.set("mike", "man");
            } else {
                r.set("丽丽", "女女女女女女");
            }
            x = (x + 1) % 2;
        }
    }
}

class Output0 implements Runnable {
    private Res0 r;

    Output0(Res0 r) {
        this.r = r;
    }

    public void run() {
        while (true) {
            r.out();
        }
    }
}

public class InputOutputDemo0 {
    public static void main(String[] args) {
        Res0 r = new Res0();
        new Thread(new Input0(r)).start();
        new Thread(new Output0(r)).start();
    }
}
//输出
mike.....man
丽丽.....女女女女女女
mike.....man
丽丽.....女女女女女女
mike.....man
丽丽.....女女女女女女
mike.....man
丽丽.....女女女女女女
mike.....man
丽丽.....女女女女女女

多个生产者和消费者情况

class Resource
{
    private String name;
    private int count = 1;
    private boolean flag = false;
    public synchronized void set(String name)
    {
        while(flag)
            try { this.wait(); }catch (InterruptedException e){}
        this.name = name+"--"+count++;
        System.out.println(Thread.currentThread().getName()+".....生产者"+this.name);
        flag = true;
        this.notifyAll();
    }
    public synchronized void out()
    {
        while(!flag)
            try { this.wait(); }catch (InterruptedException e){}
        System.out.println(Thread.currentThread().getName()+"......消费者"+this.name);
        flag = false;
        this.notifyAll();
    }
}
class Producer implements Runnable {
    private Resource res;

    Producer(Resource res)
    {
        this.res = res;
    }
    public void run()
    {
        while (true)
//        for (int i = 0;i<1000;i++)
        res.set("+商品+");
    }
}
class Consumer implements Runnable
{
    private Resource res;
    Consumer(Resource res)
    {
        this.res = res;
    }
    public void  run()
    {
        while (true)
//        for (int i = 0;i<1000;i++)
        res.out();
    }
}
public class ProducerConsumerDemo {
    public static void main(String[] args) {
        Resource res = new Resource();
        Producer p1 = new Producer(res);
        Consumer c1 = new Consumer(res);
        Thread t1 = new Thread(p1);
        Thread t2 = new Thread(p1);
        Thread t3 = new Thread(c1);
        Thread t4 = new Thread(c1);

        t1.start();
        t2.start();
        t3.start();
        t4.start();
    }
}
为什么要定义while判断标记。
原因:让被唤醒的线程再一次判断标记。
为什么定义nofigyAll,因为需要唤醒对方线程。因为只用notify,容易出现只唤醒本方线程的情况,导致程序中的所有线程都等待。

JDK1.5.0中提供了多线程升级解决方案。将同步Synchronized替换成显示Lock操作。将Object中的wait,notify,notifyAll,替换了Condition对象。该对象可以Lock锁进行获取。该示例中,实现了本方只唤醒本方操作。

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

class Resource0
{
    private String name;
    private int count = 1;
    private boolean flag = false;
    private Lock lock = new ReentrantLock();
    private Condition condition = lock.newCondition();
    public void set(String name)throws InterruptedException
    {
        lock.lock();
        try{
            while(flag)
                condition.await();
            this.name = name+"--"+count++;
            System.out.println(Thread.currentThread().getName()+".....生产者"+this.name);
            flag = true;
            condition.signal();
        }
        finally {
            lock.unlock();
        }
    }
    public void out() throws InterruptedException
    {
        lock.lock();
        try {
            while(!flag)
                condition.await();
            System.out.println(Thread.currentThread().getName()+"......消费者"+this.name);
            flag = false;
            condition.signal();
        }
        finally {
            lock.unlock();
        }
    }
}
class Producer0 implements Runnable {
    private Resource0 res;

    Producer0(Resource0 res)
    {
        this.res = res;
    }
    public void run()
    {
        while (true)
            try{
                //        for (int i = 0;i<1000;i++)
                res.set("+商品+");
            }
            catch (InterruptedException e)
            {

            }
    }
}
class Consumer0 implements Runnable
{
    private Resource0 res;
    Consumer0(Resource0 res)
    {
        this.res = res;
    }
    public void  run()
    {
        while (true)
            try {
                //        for (int i = 0;i<1000;i++)
                res.out();
            }catch (InterruptedException e)
            {

            }

    }
}
public class ProducerConsumerDemo0 {
    public static void main(String[] args) {
        Resource0 res = new Resource0();
        Producer0 p1 = new Producer0(res);
        Consumer0 c1 = new Consumer0(res);
        Thread t1 = new Thread(p1);
        Thread t2 = new Thread(p1);
        Thread t3 = new Thread(c1);
        Thread t4 = new Thread(c1);

        t1.start();
        t2.start();
        t3.start();
        t4.start();
    }
}
//输出:全部唤醒,程序无法结束
0.gif

condition.signal()唤醒本方线程,造成相互等待程序无法结束。

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

class Resource0
{
    private String name;
    private int count = 1;
    private boolean flag = false;
    private Lock lock = new ReentrantLock();
    private Condition condition = lock.newCondition();
    public void set(String name)throws InterruptedException
    {
        lock.lock();
        try{
            while(flag)
                condition.await();
            this.name = name+"--"+count++;
            System.out.println(Thread.currentThread().getName()+".....生产者"+this.name);
            flag = true;
            condition.signalAll();
        }
        finally {
            lock.unlock();
        }
    }
    public void out() throws InterruptedException
    {
        lock.lock();
        try {
            while(!flag)
                condition.await();
            System.out.println(Thread.currentThread().getName()+"......消费者"+this.name);
            flag = false;
            condition.signalAll();
        }
        finally {
            lock.unlock();
        }
    }
}
class Producer0 implements Runnable {
    private Resource0 res;

    Producer0(Resource0 res)
    {
        this.res = res;
    }
    public void run()
    {
        while (true)
            try{
                //        for (int i = 0;i<1000;i++)
                res.set("+商品+");
            }
            catch (InterruptedException e)
            {

            }
    }
}
class Consumer0 implements Runnable
{
    private Resource0 res;
    Consumer0(Resource0 res)
    {
        this.res = res;
    }
    public void  run()
    {
        while (true)
            try {
                //        for (int i = 0;i<1000;i++)
                res.out();
            }catch (InterruptedException e)
            {

            }

    }
}
public class ProducerConsumerDemo0 {
    public static void main(String[] args) {
        Resource0 res = new Resource0();
        Producer0 p1 = new Producer0(res);
        Consumer0 c1 = new Consumer0(res);
        Thread t1 = new Thread(p1);
        Thread t2 = new Thread(p1);
        Thread t3 = new Thread(c1);
        Thread t4 = new Thread(c1);

        t1.start();
        t2.start();
        t3.start();
        t4.start();
    }
}
//输出正常
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

class Resource0
{
    private String name;
    private int count = 1;
    private boolean flag = false;
    private Lock lock = new ReentrantLock();
    private Condition condition_pro = lock.newCondition();
    private Condition condition_con = lock.newCondition();

//    private Condition condition = lock.newCondition();

    public void set(String name)throws InterruptedException
    {
        lock.lock();
        try{
            while(flag)
                condition_pro.await();
            this.name = name+"--"+count++;
            System.out.println(Thread.currentThread().getName()+"...生产者"+this.name);
            flag = true;
            condition_con.signal();
        }
        finally {
            lock.unlock();
        }
    }
    public void out() throws InterruptedException
    {
        lock.lock();
        try {
            while(!flag)
                condition_con.await();
            System.out.println(Thread.currentThread().getName()+"..消费者"+this.name);
            flag = false;
            condition_pro.signal();
        }
        finally {
            lock.unlock();
        }
    }
}
class Producer0 implements Runnable {
    private Resource0 res;

    Producer0(Resource0 res)
    {
        this.res = res;
    }
    public void run()
    {
        while (true)
            try{
                //        for (int i = 0;i<1000;i++)
                res.set("+商品+");
            }
            catch (InterruptedException e)
            {

            }
    }
}
class Consumer0 implements Runnable
{
    private Resource0 res;
    Consumer0(Resource0 res)
    {
        this.res = res;
    }
    public void  run()
    {
        while (true)
            try {
                //        for (int i = 0;i<1000;i++)
                res.out();
            }catch (InterruptedException e)
            {

            }

    }
}
public class ProducerConsumerDemo0 {
    public static void main(String[] args) {
        Resource0 res = new Resource0();
        Producer0 p1 = new Producer0(res);
        Consumer0 c1 = new Consumer0(res);
        Thread t1 = new Thread(p1);
        Thread t2 = new Thread(p1);
        Thread t3 = new Thread(c1);
        Thread t4 = new Thread(c1);

        t1.start();
        t2.start();
        t3.start();
        t4.start();
    }
}
//输出正常

停止线程

stop方法已经过时。
如何停止线程?
只有一种,run方法结束。开启多线程运行,运行代码通常是循环结构。只要控制住循环,就可以让run方法结束,也就是线程结束。

特殊情况:当线程处于了冻结状态。
就不会读取到标记,那么线程就不会结束。
当没有指定的方式让冻结的线程恢复到运行状态时,这时需要对冻结状态进行清除。
强制让线程恢复到运行状态中来。这样就可以操作标记让线程结束。
Thread类提供了该方法interrupt();

class  StopThread implements Runnable
{
    private Boolean flag = true;
    public void run()
    {
       while (flag)
       {
           System.out.println(Thread.currentThread().getName()+"...run");
       }
    }
    public void changeFlag()
    {
        flag = false;
    }
}
public class StopThreadDemo {
    public static void main(String[] args) {
        StopThread st = new StopThread();

        Thread t1 = new Thread(st);
        Thread t2 = new Thread(st);

        t1.start();
        t2.start();

        int num = 0;

        while (true)
        {
            if (num++ == 60)
            {
                st.changeFlag();
                break;
            }
            System.out.println(Thread.currentThread().getName()+"......"+num);
        }
    }
}
//输出正常:num到60,改变标记flag,结束循环,结束打印,结束线程。
...
main......50
Thread-0...run
main......51
Thread-1...run
main......52
Thread-0...run
main......53
Thread-1...run
main......54
Thread-0...run
main......55
Thread-1...run
main......56
main......57
main......58
Thread-0...run
Thread-0...run
main......59
Thread-1...run
main......60
Thread-0...run
Thread-1...run

线程无法中断

class  StopThread0 implements Runnable
{
    private Boolean flag = true;
    public synchronized void run()
    {
        while (flag)
        {
            try{
                wait();
            }catch (InterruptedException e)
            {
                System.out.println(Thread.currentThread().getName()+"...run"+e.toString());
            }
            System.out.println(Thread.currentThread().getName()+"...run");
        }
    }
    public void changeFlag()
    {
        flag = false;
    }
}
public class StopThreadDemo0 {
    public static void main(String[] args) {
        StopThread0 st = new StopThread0();

        Thread t1 = new Thread(st);
        Thread t2 = new Thread(st);

        t1.start();
        t2.start();

        int num = 0;

        while (true)
        {
            if (num++ == 60)
            {
                st.changeFlag();
                break;
            }
            System.out.println(Thread.currentThread().getName()+"......"+num);
        }
        System.out.println(Thread.currentThread().getName()+"over");
    }
}
//输出:程序无法结束
2.gif
class  StopThread0 implements Runnable
{
    private Boolean flag = true;
    public synchronized void run()
    {
        while (flag)
        {
            try{
                wait();
            }catch (InterruptedException e)
            {
                System.out.println(Thread.currentThread().getName()+"...run"+e.toString());
            }
            System.out.println(Thread.currentThread().getName()+"...run");
        }
    }
    public void changeFlag()
    {
        flag = false;
    }
}
public class StopThreadDemo0 {
    public static void main(String[] args) {
        StopThread0 st = new StopThread0();

        Thread t1 = new Thread(st);
        Thread t2 = new Thread(st);

        t1.start();
        t2.start();

        int num = 0;

        while (true)
        {
            if (num++ == 60)
            {
//                st.changeFlag();
                t1.interrupt();
                t2.interrupt();
                break;
            }
            System.out.println(Thread.currentThread().getName()+"......"+num);
        }
        System.out.println(Thread.currentThread().getName()+"over");
    }
}
//输出:程序无法结束
4.gif

程序结束

class  StopThread0 implements Runnable
{
    private Boolean flag = true;
    public synchronized void run()
    {
        while (flag)
        {
            try{
                wait();
            }catch (InterruptedException e)
            {
                System.out.println(Thread.currentThread().getName()+"...run"+e.toString());
                flag = false;
            }
            System.out.println(Thread.currentThread().getName()+"...run");
        }
    }
    public void changeFlag()
    {
        flag = false;
    }
}
public class StopThreadDemo0 {
    public static void main(String[] args) {
        StopThread0 st = new StopThread0();

        Thread t1 = new Thread(st);
        Thread t2 = new Thread(st);

        t1.start();
        t2.start();

        int num = 0;

        while (true)
        {
            if (num++ == 60)
            {
//                st.changeFlag();
                t1.interrupt();
                t2.interrupt();
                break;
            }
            System.out.println(Thread.currentThread().getName()+"......"+num);
        }
        System.out.println(Thread.currentThread().getName()+"over");
    }
}
//输出正常
main......50
main......51
main......52
main......53
main......54
main......55
main......56
main......57
main......58
main......59
main......60
mainover
Thread-0...runjava.lang.InterruptedException
Thread-0...run
Thread-1...runjava.lang.InterruptedException
Thread-1...run

守护线程

class  StopThread1 implements Runnable
{
    private Boolean flag = true;
    public void run()
    {
        while (flag)
        {
            System.out.println(Thread.currentThread().getName()+"...run");
        }
    }
    public void changeFlag()
    {
        flag = false;
    }
}
public class StopThreadDemo1 {
    public static void main(String[] args) {
        StopThread1 st = new StopThread1();

        Thread t1 = new Thread(st);
        Thread t2 = new Thread(st);

        t1.setDaemon(true);
        t2.setDaemon(true);
        t1.start();
        t2.start();

        int num = 0;

        while (true)
        {
            if (num++ == 60)
            {
//                st.changeFlag();
//                t1.interrupt();
//                t2.interrupt();
                break;
            }
            System.out.println(Thread.currentThread().getName()+"......"+num);
        }
        System.out.println(Thread.currentThread().getName()+"over");
    }
}
//输出
Thread-0...run
main......58
Thread-1...run
main......59
Thread-0...run
Thread-0...run
main......60
Thread-1...run
Thread-0...run
Thread-0...run
Thread-0...run
Thread-1...run
Thread-1...run
Thread-0...run
Thread-0...run
Thread-1...run
Thread-0...run
mainover
Thread-1...run
Thread-0...run
Thread-1...run
Thread-0...run
Thread-1...run
Thread-0...run
Thread-1...run
Thread-0...run
Thread-1...run
Thread-0...run

join方法:当A线程执行到了B线程的.join()方法时,A就会等待。等B线程都执行完,A才会执行。join可以用来临时加入线程执行。

class Demo6 implements Runnable
{
    public void run()
    {
        for (int x = 0;x<60;x++)
        {
            System.out.println(Thread.currentThread().getName()+"....."+x);
        }
    }
}
public class JoinDemo {
    public static void main(String[] args) throws InterruptedException
    {
       Demo6 d = new Demo6();
       Thread t1 = new Thread(d);
       Thread t2 = new Thread(d);
       t1.start();
       t1.join();
       t2.start();

       for (int x=0;x<70;x++)
       {
           System.out.println("main......"+x);
       }
       System.out.println("over");
    }
}
//输出:t1线程执行完才回到主线程
...
Thread-0.....55
Thread-0.....56
Thread-0.....57
Thread-0.....58
Thread-0.....59
Thread-1.....0
Thread-1.....1
Thread-1.....2
...

优先级

class Demo7 implements Runnable
{
    public void run()
    {
        for (int x = 0;x<60;x++)
        {
            System.out.println(Thread.currentThread().toString()+"....."+x);
        }
    }
}
public class PriorityYeildDemo {
    public static void main(String[] args) throws InterruptedException
    {
        Demo7 d = new Demo7();
        Thread t1 = new Thread(d);
        Thread t2 = new Thread(d);
        t1.start();
        t1.setPriority(Thread.MAX_PRIORITY);
        t2.start();

        for (int x=0;x<70;x++)
        {
            System.out.println("main......"+x);
        }
        System.out.println("over");
    }
}
//输出:优先级为10
Thread[Thread-1,5,main].....0
Thread[Thread-0,10,main].....0
Thread[Thread-1,5,main].....1
Thread[Thread-0,10,main].....1
Thread[Thread-1,5,main].....2
Thread[Thread-0,10,main].....2
...
Thread[Thread-1,5,main].....57
Thread[Thread-0,10,main].....56
Thread[Thread-1,5,main].....58
Thread[Thread-0,10,main].....57
Thread[Thread-1,5,main].....59
Thread[Thread-0,10,main].....58
Thread[Thread-0,10,main].....59

yield

class Demo7 implements Runnable
{
    public void run()
    {
        for (int x = 0;x<60;x++)
        {
            System.out.println(Thread.currentThread().toString()+"....."+x);
            Thread.yield();
        }
    }
}
public class PriorityYeildDemo {
    public static void main(String[] args) throws InterruptedException
    {
        Demo7 d = new Demo7();
        Thread t1 = new Thread(d);
        Thread t2 = new Thread(d);
        t1.start();
        t2.start();

        for (int x=0;x<70;x++)
        {
            System.out.println("main......"+x);
        }
        System.out.println("over");
    }
}
//输出:中断当前线程,线程交替更频繁
Thread[Thread-0,5,main].....0
Thread[Thread-0,5,main].....1
Thread[Thread-0,5,main].....2
Thread[Thread-1,5,main].....0
Thread[Thread-0,5,main].....3
Thread[Thread-1,5,main].....1
Thread[Thread-0,5,main].....4
Thread[Thread-1,5,main].....2
Thread[Thread-0,5,main].....5
Thread[Thread-1,5,main].....3
Thread[Thread-0,5,main].....6

多线程的使用:匿名内部类,继承或实现封装

public class ThreadTest {
    public static void main(String[] args) {
        new Thread(){
            public void run()
            {
                for (int x = 0;x <100;x++)
                {
                    System.out.println(Thread.currentThread().toString()+"..."+x);
                }
            }
        }.start();

        for (int x = 0;x <100;x++)
        {
            System.out.println(Thread.currentThread().toString()+"..."+x);
        }

        Runnable r = new Runnable(){
            public void  run()
            {
                for (int x = 0;x <100;x++)
                {
                    System.out.println(Thread.currentThread().toString()+"..."+x);
                }
            }
        };
        new Thread(r).start();
    }
}
//封装
class Demo8 extends Thread
{
    public void run()
    {
        for (int x = 0;x <100;x++)
        {
            System.out.println(Thread.currentThread().toString()+"..."+x);
        }
    }
}
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,835评论 4 364
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,598评论 1 295
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 109,569评论 0 244
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,159评论 0 213
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,533评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,710评论 1 222
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,923评论 2 313
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,674评论 0 203
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,421评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,622评论 2 245
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,115评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,428评论 2 254
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,114评论 3 238
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,097评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,875评论 0 197
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,753评论 2 276
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,649评论 2 271

推荐阅读更多精彩内容

  • Java多线程学习 [-] 一扩展javalangThread类 二实现javalangRunnable接口 三T...
    影驰阅读 2,922评论 1 18
  • 本文主要讲了java中多线程的使用方法、线程同步、线程数据传递、线程状态及相应的一些线程函数用法、概述等。 首先讲...
    李欣阳阅读 2,377评论 1 15
  • 三、多线程: 1、进程和线程: 进程:正在进行的程序。每一个进程执行都有一个执行顺序,该顺序是一个执行路径,或者叫...
    佘大将军阅读 292评论 0 0
  • 林炳文Evankaka原创作品。转载自http://blog.csdn.net/evankaka 本文主要讲了ja...
    ccq_inori阅读 620评论 0 4
  • 多线程 1、进程和线程 进程:正在进行的成序。每一个进程执行都有一个执行顺序,该顺序是一个执行路径,或者叫一个控制...
    有_味阅读 285评论 1 1