首页 / 更多教程 / JUC详解 消费者生产者
JUC详解 消费者生产者
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了JUC详解 消费者生产者,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1686字,纯文字阅读大概需要3分钟。
内容图文
![JUC详解 消费者生产者](/upload/InfoBanner/zyjiaocheng/1035/7674421b3e8f491eb81b0534e59a030a.jpg)
1.1.1 JUC并发升级
业务:普通的线程代码 Thread
Runnable 没有返回值 效率相比callable低
1.1.2线程和进程
一句话说不出来的技术 就是不扎实
java 默认有几个线程 2个 main 和GC
java真的可以开启线程吗
public synchronized void start() {
/**
* This method is not invoked for the main method thread or "system"
* group threads created/set up by the VM. Any new functionality added
* to this method in the future may have to also be added to the VM.
*
* A zero status value corresponds to state "NEW".
*/
if (threadStatus != 0)
throw new IllegalThreadStateException();
/* Notify the group that this thread is about to be started
* so that it can be added to the group's list of threads
* and the group's unstarted count can be decremented. */
group.add(this);
boolean started = false;
try {
start0();
started = true;
} finally {
try {
if (!started) {
group.threadStartFailed(this);
}
} catch (Throwable ignore) {
/* do nothing. If start0 threw a Throwable then
it will be passed up the call stack */
}
}
}
//底层调用native方法 使用c++编写
private native void start0();
底层调用native方法 使用c++编写
1.1.3 并发和并行
并发 (多线程操作一个资源)
- 一核 ,交替运行 ,造成假象
并行 优化使用线程池
- 多核心cpu ,多个线程可以同时执行
查看本机有几核
package com.cjg.juc;
public class demo01 {
public static void main(String[] args) {
// new Thread().start();
//获取cpu的核数
//cpu 密集型 和io密集型
System.out.println(Runtime.getRuntime().availableProcessors());
}
}
并发的本质:充分利用cpu的资源
线程有几个状态
新生
NEW,
运行
RUNNABLE,
阻塞
BLOCKED,
等待 死等
WAITING,
超时等待
TIMED_WAITING,
终止
TERMINATED;
}
wait/sleep 区别
wait ==>object
标签:,,,,,,,, 来源: https://blog.csdn.net/weixin_50224527/article/details/114897279
内容总结
以上是互联网集市为您收集整理的JUC详解 消费者生产者全部内容,希望文章能够帮你解决JUC详解 消费者生产者所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。