`
huhu_long
  • 浏览: 73692 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

10/18/2011 - Thread 相关

阅读更多
1. 进程是资源的占有者,线程是资源的使用者。
2. 进程本身不能执行,它只是一个资源的集合体,拥有地址空间,模块,内存。
3. 线程是真正的执行单元,一个进程如果没有线程,那么就没有存在的意义,因为不可能执行。
------------------------ 我是分割线 ----------------------------------
4. 线程池:
   a) 创建线程目标对象,其实就是Runnable对象
   b) 使用Executors创建线程池,返回一个ExecutorService类型的对象
   c) 使用线程池执行线程目标对象,即:exec.execute(run);
   d) 最后线程池结束线程,exec.shutdown().
------------------------ 我是分割线 ----------------------------------
5. volatile 可以安全的替代锁的两个条件:
   a) 对变量的写操作不依赖于当前值。
   b) 该变量没有包含在具有其他变量的不变式中。
   如:
   针对条件1,i++ i-- 这样的操作是不能用volatile 替代
   针对条件2,if (volatileVar > num) 这样的形式也不能用volatile 替代锁
------------------------ 我是分割线 ----------------------------------
6. ThreadLocal 会为每一个线程提供一个独立的变量副本. 每个线程在使用ThreadLocal 变量的get方法的时候都会先执行initialValue()方法, 如果先执行了set方法就不会再执行initialValue()方法。如果程序员希望将ThreadLocal 变量初始化为 null 以外的某个值则必须实现initialValue()方法。
对于每个线程ThreadLocal变量不存在影响他们之间协作的状态,为每个线程创建一个ThreadLocal变量的拷贝或者叫做副本。
------------------------ 我是分割线 ----------------------------------
7. 同步机制采用了“以时间换空间”的方式,而 ThreadLocal 采用了“以空间换时间”的方式。
------------------------ 我是分割线 ----------------------------------
8. Concurrent 包下面主要提供了一些线程安全的数据结构,最经典的就是 生产者-消费者 问题 用阻塞队列的实现。 ArrayBlockingQueue / LinkedBlockingQueue. 还有就是Map 与 ConcurrentMap, ConcurrentMap的所有方法都是原子的。 比如: Map中得 put 方法对应的方法是 putIfAbsent.
------------------------ 我是分割线 ----------------------------------







分享到:
评论

相关推荐

    http://www.dospy.com/bbs/thread-455344-1-7.htmljay

    http://www.dospy.com/bbs/thread-455344-1-7.html

    Linux编译静态链接出现:/usr/bin/ld: cannot find -lc,解决方式

    Linux编译静态链接出现:/usr/bin/ld: cannot find -lc. 将libc.a拷贝到usr/lib/中,问题得以解决。

    arm-2014.05-29-arm-none-linux-gnueabi

    arm-none-linux-gnueabi-gcc.exe -v Using built-in specs. COLLECT_GCC=arm-none-linux-gnueabi-gcc.exe ...Thread model: posix gcc version 4.8.3 20140320 (prerelease) (Sourcery CodeBench Lite

    /usr/bin/ld:cannot find-lThreads的解决办法

    target_link_libraries(MyProject ${CMAKE_THREAD_LIBS_INIT}) ``` - **方法二:直接设置链接标志** 如果你选择不使用`find_package`,也可以手动添加链接标志。在CMakeLists.txt中,可以使用`CMAKE_C_FLAGS`或...

    12http://www.3che.com/thread-233-1-1.html

    因此,深入理解D/A转换的原理、组成以及相关技术参数对于设计和应用这一技术至关重要。 首先,我们来探讨一下D/A转换器的内部工作原理。D/A转换器的核心任务是将数字信号转换为模拟信号。数字信号是由一系列0和1...

    arm-linux-gcc交叉编译器 4.3.2 part2

    arm-linux-gcc交叉编译器,版本4.3.2,用于Linux下的ARM开发。 本文件为arm-linux-gcc-4.3.2.tgz的part2 arm-linux-gcc-4.3.2.tgz.ab,需要与...Thread model: posix gcc version 4.3.2 (Sourcery G++ Lite 2008q3-72)

    ubuntu18.04卸载mysql并重新安装的方法.doc

    `thread_stack = 192K` 然后,重新执行卸载和安装MySQL服务器的命令: `sudo rm /var/lib/mysql/ -R` `sudo rm /etc/mysql/ -R` `sudo apt-get autoremove mysql* --purge` `sudo apt-get install mysql-server ...

    微信小程序Demo:点餐小程序

    微信小程序Demo:点餐小程序 项目地址:http://www.wxapp-union.com/thread-9772-1-1.html

    200_LTM_1030-2.1_PN_200.00.E09.2009_8986-0.pdf

    利勃海尔1030的工况表...1727452-1-1.htmlhttps://chiphell.com/thread-1727452-1-1.htmlhttps://chiphell.com/thread-1727452-1-1.html

    RT-Thread Simulator 例程

    https://gitee.com/rtthread/docs-online/raw/master/rt-thread-version/rt-thread-standard/tutorial/quick-start/stm32f103-simulator/rtthread_simulator_v0.1.0.7z 发现很多官方例程需要很高的积分,没必要啊,...

    spring-boot示例项目

    本项目示例基于spring boot 最新版本(2.1.9)实现,Spring Boot、Spring Cloud 学习示例,将持续更新…… 在基于Spring Boot、Spring Cloud 分布微服务开发过程中,根据实际项目环境,需要选择、集成符合项目...

    arm-linux-gcc-4.3.2(交叉编译器)

    arm-linux-gcc交叉编译器,版本3.4.1,用于Linux下的ARM开发。 安装方法: 1. tar zxvf arm-linux-gcc-3.4.1.tgz -C/ 2. 编辑 ~/.bashrc ,加入 export PATH=$PATH:/usr/...Thread model: posix gcc version 3.4.1。

    http://bbs.qinjing.cc/thread-20687-1-1.html

    【计算机专业研究生入学考试大纲解析】 计算机专业研究生入学考试主要围绕四门核心课程展开:数据结构、计算机组成原理、操作系统和计算机网络。这四门课程分别构成了软件理论和硬件理论的基础,是计算机科学的基石...

    哈佛大学公开课

    耶鲁大学开放课程:有关食物的心理学,生物学和政治学 http://www.manfen.net/thread-7275-1-1.html 耶鲁课程.:欧洲文明 http://www.manfen.net/thread-7074-1-1.html 耶鲁大学开放课-金融市场 ...

    Mainly using AMG8833, RT-Thread and NNOM libs to run heat-map r

    Mainly using AMG8833, RT-Thread and NNOM libs to run heat-map recognition and setup neural network on STM32F4 (1). Introduction: This project is my first attempt to do a neural network recognizing ...

    arm-cortexa9_neon-linux-uclibcgnueabihf-gcc-7.4.0.tar.bz2

    Using built-in specs. COLLECT_GCC=./arm-cortexa9_neon-linux-uclibcgnueabihf-gcc COLLECT_LTO_WRAPPER=/opt/toolchains/arm-cortexa9_neon-linux-...Thread model: posix gcc version 7.4.0 (crosstool-NG 1.24.0)

    Android代码-launcher

    La/u/ncher 4.2.5 Try it in your browser! ...Try it on your phone! ... ...Changing the bar color won't take full effect ...Creating a new thread, then going to the thread watcher and unwatching it, then replyi

    解决RT-Thread Studio包管理失败的更新文件

    RT-Thread Studio包管理失败,原因就是\platform\env_released\env\tools\Python27\DLLs的_ssl.pyd文件有bug,用该更新文件替换后将会解决问题。

    arm-linux-gcc交叉编译器 4.3.2 part1

    arm-linux-gcc交叉编译器 4.3.2 part1 arm-linux-gcc-4.3.2.tgz.aa 需要与part2 arm-linux-gcc-4.3.2.tgz.ab 合并成arm-linux-gcc-4.3.2.tgz ...Thread model: posix gcc version 4.3.2 (Sourcery G++ Lite 2008q3-72)

    arm-linux-gcc-3.4.1(交叉编译器)

    arm-linux-gcc交叉编译器,版本3.4.1,用于Linux下的ARM开发。 安装方法: 1. tar zxvf arm-linux-gcc-3.4.1.tgz -C/ 2. 编辑 ~/.bashrc ,加入 export PATH=$PATH:/usr/...Thread model: posix gcc version 3.4.1。

Global site tag (gtag.js) - Google Analytics