volatile

测试开发工程师面试总结(一)——Java基础篇

微笑、不失礼 提交于 2019-12-01 18:12:43
本文面向对象:测试开发工程师(服务端自动化方向)。 随手百度一下都能找到**岗位面试总结,但是有关测开岗位的面试总结却寥寥无几。总体原因可能是这两个:1 测试行业整体水平参差不齐,导致不同公司面试的问题不能抽象出来写概览。2 很多做测开的人可能内心对这个行业缺少热爱,所以不爱去写。 在找工作的过程中发现测开被问到的非常杂,涵盖了Java基础(因为我平时使用Java语言较多)、算法、Spring基础、Linux基本命令、测试工具selenium等。现在把以上五个方面分五篇总结。 Java基础 1. 最基础的是问到Java的基本类型,引用类型 基本类型一共有八种,六种数字类型(四个整数型两个浮点型),一种字符类型,还有一种布尔型,整数型包括byte 8位 short 16位 int 32位 long64位,字符型即char 16位的Unicode字符 ,布尔型表示一位的信息。引用类型指向一个对象,指向对象的变量就是引用变量。对象 数组都是引用类型。 2. 字符串string类和stringbuffer的区别也是经常考查到的点 String类是不可变的,如果对字符串进行修改,需要使用StringBuffer和StringBuilder。StringBuffer是线程安全的,StringBuilder在Java5中被提出,她相较于StringBuffer有速度优势但是是线程不安全的

'volatile' in method signature? [duplicate]

北城以北 提交于 2019-12-01 17:54:08
This question already has an answer here: Why make a method volatile in java? 7 answers This one is weird. I have the following code: class A { protected A clone() throws CloneNotSupportedException { return (A) super.clone(); } } when I de-compiled its bytecode through 'showmycode.com', it showed me the following code: class A { A() { } protected A clone() throws clonenotsupportedexception { return (A)super.clone(); } protected volatile object clone() throws clonenotsupportedexception { return clone(); } } What does it mean for a method return type to be volatile in the second 'clone' method?

'volatile' in method signature? [duplicate]

好久不见. 提交于 2019-12-01 16:52:37
问题 This question already has answers here : Why make a method volatile in java? (7 answers) Closed 5 years ago . This one is weird. I have the following code: class A { protected A clone() throws CloneNotSupportedException { return (A) super.clone(); } } when I de-compiled its bytecode through 'showmycode.com', it showed me the following code: class A { A() { } protected A clone() throws clonenotsupportedexception { return (A)super.clone(); } protected volatile object clone() throws

java并发之AtomicInteger源码分析

谁说胖子不能爱 提交于 2019-12-01 16:39:03
AtomicInteger是java并发包下面提供的原子类,主要操作的是int类型的整型,通过调用底层Unsafe的CAS等方法实现原子操作。 原子操作 是指不会被线程调度机制打断的操作,这种操作一旦开始,就一直运行到结束,中间不会有任何线程上下文切换。 原子操作可以是一个步骤,也可以是多个操作步骤,但是其顺序不可以被打乱,也不可以被切割而只执行其中的一部分,将整个操作视作一个整体是原子性的核心特征。 我们这里说的原子操作与数据库 ACID中的原子性,笔者认为最大区别在于,数据库中的原子性主要运用在事务中,一个事务之内的所有更新操作要么都成功,要么都失败,事务是有回滚机制的,而我们这里说的原子操作是没有回滚的,这是最大的区别。 主要属性 // 获取Unsafe的实例 private static final Unsafe unsafe = Unsafe.getUnsafe(); // 标识value字段的偏移量 private static final long valueOffset; // 静态代码块,通过unsafe获取value的偏移量 static { try { valueOffset = unsafe.objectFieldOffset (AtomicInteger.class.getDeclaredField("value")); } catch

嵌入式经典问题汇总

我与影子孤独终老i 提交于 2019-12-01 15:39:38
1) 对于整形变量A=0x12345678,请画出在little endian及big endian的方式下在内存中是如何存储的 。 little endian big endian 刚好反过来 高地址--〉 0x12 低地址--〉 0x12 0x34 0x34 0x56 0x56 低地址--〉 0x78 高地址--〉 0x78 2) 在ARM系统中,函数调用的时候,参数是通过哪种方式传递的? 参数<=4时候,通过R0~R3传递,>4的通过压栈方式传递 3) 中断(interrupt,如键盘中断)与异常(exception,如除零异常)有何区别? 异常:在产生时必须考虑与处理器的时钟同步,实际上,异常也称为同步中断。在处理器执行到由于编程失误而导致的错误指令时,或者在执行期间出现特殊情况(如缺页),必须靠内核处理的时候,处理器就会产生一个异常。 所谓中断应该是指外部硬件产生的一个电信号,从cpu的中断引脚进入,打断cpu当前的运行; 所谓异常,是指软件运行中发生了一些必须作出处理的事件,cpu自动产生一个信号来打断当前运行,转入异常处理流程。 2 . 写一个"标准"宏MIN ,这个宏输入两个参数并返回较小的一个。 #define MIN(A,B) ((A) <= (B) ? (A) : (B)) 【 程序员面试宝典 】 这个测试是为下面的目的而设的: 1) 标识

设计模式——单例模式

不羁岁月 提交于 2019-12-01 15:07:19
单例模式 (Singleton Pattern)使用的比较多,比如我们的 controller 和 service 都是单例的,但是其和标准的单例模式是有区别的。这种类型的设计模式属于创建型模式,它提供了一种创建对象的最佳方式。这种模式涉及到一个单一的类,该类负责创建自己的对象,同时确保只有单个对象被创建。这个类提供了一种访问其唯一的对象的方式,可以直接访问,不需要实例化该类的对象。 模式结构 单例模式的结构很简单,只涉及到一个单例类,这个单例类的构造方法是私有的,该类自身定义了一个静态私有实例,并向外提供一个静态的公有函数用于创建或获取该静态私有实例。 源码导读 单例模式分为懒汉单例和饿汉单例;饿汉单例代码很简单,顾名思义,饿汉单例就是类初始化的时候就将该单例创建,示例代码如下: public class Singleton { private static final Singleton singleton = new Singleton(); //限制产生多个对象 private Singleton(){ } //通过该方法获得实例对象 public static Singleton getSingleton(){ return singleton; } //类中其他方法,尽量是 static public static void doSomething(){ } }

Why is volatile keyword not needed for thread synchronisation?

邮差的信 提交于 2019-12-01 14:49:16
问题 I am reading that the volatile keyword is not suitable for thread synchronisation and in fact it is not needed for these purposes at all. While I understand that using this keyword is not sufficient, I fail to understand why is it completely unnecessary. For example, assume we have two threads, thread A that only reads from a shared variable and thread B that only writes to a shared variable. Proper synchronisation by e.g. pthreads mutexes is enforced. IIUC, without the volatile keyword, the

Synchronizing an object shared across threads, but not accessed concurrently

不打扰是莪最后的温柔 提交于 2019-12-01 14:28:04
Let's say I have a shared object with field data . Multiple threads will share a reference to this object in order to access the field. The threads never access the object concurrently, though. Do I need to declare data as volatile? Such a situation would be the following: A class Counter defines a unique field value and one method increment . A thread increments the counter, then spawn another thread that increments the counter, etc. Given the very logic of the program, there is no concurrent access to the counter. The counter is however shared accross multiple threads. Must the counter be a

2D Volatile arrays: will self-assignment help or do I need AtomicIntegerArray?

十年热恋 提交于 2019-12-01 13:50:39
I'm writing an audio DSP application and I've opted to use a producer-consumer model. I've been reading a lot about volatile and other threading issues, but I've got a couple of questions about some specifics of my case - particularly, one of the things I need to be shared between threads is an array of arrays. I have a class which represents the producer. To allow for variation in processing time the producer stores n buffers, which it will fill in rotation every time more audio data is available and pass the buffer on to the consumer thread. I'll start with my questions, and then I'll try to

Java 中的 volatile 关键字

徘徊边缘 提交于 2019-12-01 13:11:43
Java 中 volatile 关键字是一个类型修饰符。JDK 1.5 之后,对其语义进行了增强。 保证了不同线程对共享变量进行操作时的可见性,即一个线程修改了共享变量的值,共享变量修改后的值对其他线程立即可见 通过禁止编译器、CPU 指令重排序和部分 happens-before 规则,解决有序性问题 volatile 可见性的实现 在生成汇编代码指令时会在 volatile 修饰的共享变量进行写操作的时候会多出 Lock 前缀的指令 Lock 前缀的指令会引起 CPU 缓存写回内存 一个 CPU 的缓存回写到内存会导致其他 CPU 缓存了该内存地址的数据无效 volatile 变量通过缓存一致性协议保证每个线程获得最新值 缓存一致性协议保证每个 CPU 通过嗅探在总线上传播的数据来检查自己缓存的值是不是修改 当 CPU 发现自己缓存行对应的内存地址被修改,会将当前 CPU 的缓存行设置成无效状态,重新从内存中把数据读到 CPU 缓存 看一下我们之前的一个可见性问题的测试例子 package constxiong.concurrency.a014; /** * 测试可见性问题 * @author ConstXiong */ public class TestVisibility { //是否停止 变量 private static boolean stop = false;