多线程

作者: 机器不能学习 | 来源:发表于2018-09-07 20:32 被阅读0次

    为什么wait()必须要在放synchronized里面?

    Suppose d is the object we're using to invoke wait. When a thread invokes d.wait, it must own the intrinsic lock for d — otherwise an error is thrown. Invoking wait inside a synchronized method is a simple way to acquire the intrinsic lock.

    When wait is invoked, the thread releases the lock and suspends execution. At some future time, another thread will acquire the same lock and invoke Object.notifyAll, informing all threads waiting on that lock that something important has happened。

    wait()和sleep的区别

    https://m.baidu.com/sf_zd/question/571415269.html?word=wait%E6%98%AFobject%E7%9A%84%E6%96%B9%E6%B3%95&ms=1&rid=8137590166244516711

    什么是executor,是在整个项目中使用还是每次任务中使用。

    executor是concurrent包中的执行器,它会为你管理Thread对象,简化并发开发,用其执行任务,你无需在意线程的周期。最常见的情况是,单个的executor被用来创建和管理整个系统中的所有任务。

    什么时候用volatile,它一定安全吗?

    需要对一个域进行写操作,且让所有读操作都能看见这个修改值时使用。但它不能用于计数器等非原子的操作。

    堆和栈谁是线程共享谁是隔离的?

    https://blog.csdn.net/Maxiao1204/article/details/81113874

    相关文章

      网友评论

          本文标题:多线程

          本文链接:https://www.haomeiwen.com/subject/kcicgftx.html