synchronized(this)、synchronized(class)与synchronized(Object)的区别
在多线程开发中,我们经常看到synchronized(this)、synchronized(*.class)与synchronized(任意对象)这几种类型同步方法。但是是否知道这几种写法有什么区别了?下面根据代码来分析:
synchronized代码块间的同步性
- package com.zwz.thread.demo1;
- public class ObjectService {
- public void serviceMethodA(){
- try {
- synchronized (this) {
- System.out.println("A begin time="+System.currentTimeMillis());
- Thread.sleep(2000);
- System.out.println("A end time="+System.currentTimeMillis());
- }
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- public void serviceMethodB(){
- synchronized (this) {
- System.out.println("B begin time="+System.currentTimeMillis());
- System.out.println("B end time="+System.currentTimeMillis());
- }
- }
- }
package com.zwz.thread.demo1; public class ObjectService {
public void serviceMethodA(){
try {
synchronized (this) {
System.out.println("A begin time="+System.currentTimeMillis());
Thread.sleep(2000);
System.out.println("A end time="+System.currentTimeMillis());
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void serviceMethodB(){
synchronized (this) {
System.out.println("B begin time="+System.currentTimeMillis());
System.out.println("B end time="+System.currentTimeMillis());
}
}
}
- package com.zwz.thread.demo1;
- public class ThreadA extends Thread {
- private ObjectService objectService;
- public ThreadA(ObjectService objectService){
- super();
- this.objectService=objectService;
- }
- @Override
- public void run() {
- super.run();
- objectService.serviceMethodA();
- }
- }
package com.zwz.thread.demo1; public class ThreadA extends Thread {
private ObjectService objectService;
public ThreadA(ObjectService objectService){
super();
this.objectService=objectService;
}
@Override
public void run() {
super.run();
objectService.serviceMethodA();
}
}
- package com.zwz.thread.demo1;
- public class ThreadB extends Thread {
- private ObjectService objectService;
- public ThreadB(ObjectService objectService){
- super();
- this.objectService=objectService;
- }
- @Override
- public void run() {
- super.run();
- objectService.serviceMethodB();
- }
- }
package com.zwz.thread.demo1; public class ThreadB extends Thread {
private ObjectService objectService;
public ThreadB(ObjectService objectService){
super();
this.objectService=objectService;
}
@Override
public void run() {
super.run();
objectService.serviceMethodB();
}
}
- package com.zwz.thread.demo1;
- public class MainTest {
- public static void main(String[] args) {
- ObjectService service=new ObjectService();
- ThreadA a=new ThreadA(service);
- a.setName("a");
- a.start();
- ThreadB b=new ThreadB(service);
- b.setName("b");
- b.start();
- }
- }
package com.zwz.thread.demo1; public class MainTest {
public static void main(String[] args) {
ObjectService service=new ObjectService();
ThreadA a=new ThreadA(service);
a.setName("a");
a.start();
ThreadB b=new ThreadB(service);
b.setName("b");
b.start();
}
}
运行结果:
结论:
当一个线程访问ObjectService的一个synchronized (this)同步代码块时,其它线程对同一个ObjectService中其它的synchronized (this)同步代码块的访问将是堵塞,这说明synchronized (this)使用的对象监视器是一个。
验证synchronized (this)代码块是锁定当前对象
- package com.zwz.thread.demo2;
- public class ObjectService {
- public void objectMethodA(){
- System.out.println("run----objectMethodA");
- }
- public void objectMethodB(){
- synchronized (this) {
- try {
- for (int i = 1; i <= 10; i++) {
- System.out.println("synchronized thread name:"+Thread.currentThread().getName()+"-->i="+i);
- Thread.sleep(1000);
- }
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- }
package com.zwz.thread.demo2; public class ObjectService {
public void objectMethodA(){
System.out.println("run----objectMethodA");
}
public void objectMethodB(){
synchronized (this) {
try {
for (int i = 1; i <= 10; i++) {
System.out.println("synchronized thread name:"+Thread.currentThread().getName()+"-->i="+i);
Thread.sleep(1000);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
- package com.zwz.thread.demo2;
- public class ThreadA extends Thread {
- private ObjectService objectService;
- public ThreadA(ObjectService objectService) {
- super();
- this.objectService = objectService;
- }
- @Override
- public void run() {
- super.run();
- objectService.objectMethodA();
- }
- }
package com.zwz.thread.demo2; public class ThreadA extends Thread {
private ObjectService objectService; public ThreadA(ObjectService objectService) {
super();
this.objectService = objectService;
}
@Override
public void run() {
super.run();
objectService.objectMethodA();
}
}
- package com.zwz.thread.demo2;
- public class ThreadB extends Thread {
- private ObjectService objectService;
- public ThreadB(ObjectService objectService) {
- super();
- this.objectService = objectService;
- }
- @Override
- public void run() {
- super.run();
- objectService.objectMethodB();
- }
- }
package com.zwz.thread.demo2; public class ThreadB extends Thread {
private ObjectService objectService; public ThreadB(ObjectService objectService) {
super();
this.objectService = objectService;
}
@Override
public void run() {
super.run();
objectService.objectMethodB();
}
}
- package com.zwz.thread.demo2;
- public class MainTest {
- public static void main(String[] args) throws InterruptedException {
- ObjectService service=new ObjectService();
- ThreadB b=new ThreadB(service);
- b.start();
- Thread.sleep(2000);
- ThreadA a=new ThreadA(service);
- a.start();
- }
- }
package com.zwz.thread.demo2; public class MainTest {
public static void main(String[] args) throws InterruptedException {
ObjectService service=new ObjectService();
ThreadB b=new ThreadB(service);
b.start();
Thread.sleep(2000);
ThreadA a=new ThreadA(service);
a.start();
}
}
运行结果:
可以看到objectMethodA方法异步执行了,下面我们将objectMethodA()加上同步。
- package com.zwz.thread.demo2;
- public class ObjectService {
- public synchronized void objectMethodA(){
- System.out.println("run----objectMethodA");
- }
- public void objectMethodB(){
- synchronized (this) {
- try {
- for (int i = 1; i <= 10; i++) {
- System.out.println("synchronized thread name:"+Thread.currentThread().getName()+"-->i="+i);
- Thread.sleep(1000);
- }
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- }
package com.zwz.thread.demo2; public class ObjectService {
public synchronized void objectMethodA(){
System.out.println("run----objectMethodA");
}
public void objectMethodB(){
synchronized (this) {
try {
for (int i = 1; i <= 10; i++) {
System.out.println("synchronized thread name:"+Thread.currentThread().getName()+"-->i="+i);
Thread.sleep(1000);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
运行结果:
结论:
上面三个小例子我们可以知道,多个线程调用同一个对象中的不同名称的synchronized同步方法或synchronized(this)同步代码块时,是同步的。
1、synchronized同步方法
①对其它的synchronized同步方法或synchronized(this)同步代码块调用是堵塞状态;
②同一时间只有一个线程执行synchronized同步方法中的代码。
2、synchronized(this)同步代码块
①对其它的synchronized同步方法或synchronized(this)同步代码块调用是堵塞状态;
②同一时间只有一个线程执行synchronized同步方法中的代码。
将任意对象作为对象监视器
- package com.zwz.thread.demo3;
- public class ObjectService {
- private String uname;
- private String pwd;
- String lock=new String();
- public void setUserNamePassWord(String userName,String passWord){
- try {
- synchronized (lock) {
- System.out.println("thread name="+Thread.currentThread().getName()
- +" 进入代码快:"+System.currentTimeMillis());
- uname=userName;
- Thread.sleep(3000);
- pwd=passWord;
- System.out.println("thread name="+Thread.currentThread().getName()
- +" 进入代码快:"+System.currentTimeMillis()+"入参uname:"+uname+"入参pwd:"+pwd);
- }
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
package com.zwz.thread.demo3; public class ObjectService {
private String uname;
private String pwd;
String lock=new String();
public void setUserNamePassWord(String userName,String passWord){
try {
synchronized (lock) {
System.out.println("thread name="+Thread.currentThread().getName()
+" 进入代码快:"+System.currentTimeMillis());
uname=userName;
Thread.sleep(3000);
pwd=passWord;
System.out.println("thread name="+Thread.currentThread().getName()
+" 进入代码快:"+System.currentTimeMillis()+"入参uname:"+uname+"入参pwd:"+pwd);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
- package com.zwz.thread.demo3;
- public class ThreadA extends Thread {
- private ObjectService objectService;
- public ThreadA(ObjectService objectService) {
- super();
- this.objectService = objectService;
- }
- @Override
- public void run() {
- objectService.setUserNamePassWord("a", "aa");
- }
- }
package com.zwz.thread.demo3; public class ThreadA extends Thread {
private ObjectService objectService; public ThreadA(ObjectService objectService) {
super();
this.objectService = objectService;
}
@Override
public void run() {
objectService.setUserNamePassWord("a", "aa");
}
}
- package com.zwz.thread.demo3;
- public class ThreadB extends Thread {
- private ObjectService objectService;
- public ThreadB(ObjectService objectService) {
- super();
- this.objectService = objectService;
- }
- @Override
- public void run() {
- objectService.setUserNamePassWord("b", "bb");
- }
- }
package com.zwz.thread.demo3; public class ThreadB extends Thread {
private ObjectService objectService; public ThreadB(ObjectService objectService) {
super();
this.objectService = objectService;
}
@Override
public void run() {
objectService.setUserNamePassWord("b", "bb");
}
}
- package com.zwz.thread.demo3;
- public class MainTest {
- public static void main(String[] args) {
- ObjectService service=new ObjectService();
- ThreadA a=new ThreadA(service);
- a.setName("A");
- a.start();
- ThreadB b=new ThreadB(service);
- b.setName("B");
- b.start();
- }
- }
package com.zwz.thread.demo3; public class MainTest {
public static void main(String[] args) {
ObjectService service=new ObjectService();
ThreadA a=new ThreadA(service);
a.setName("A");
a.start();
ThreadB b=new ThreadB(service);
b.setName("B");
b.start();
}
}
运行结果:
下面我把String lock=new String();放在方法中会有啥结果了:
- package com.zwz.thread.demo3;
- public class ObjectService {
- private String uname;
- private String pwd;
- public void setUserNamePassWord(String userName,String passWord){
- try {
- String lock=new String();
- synchronized (lock) {
- System.out.println("thread name="+Thread.currentThread().getName()
- +" 进入代码快:"+System.currentTimeMillis());
- uname=userName;
- Thread.sleep(3000);
- pwd=passWord;
- System.out.println("thread name="+Thread.currentThread().getName()
- +" 进入代码快:"+System.currentTimeMillis()+"入参uname:"+uname+"入参pwd:"+pwd);
- }
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
package com.zwz.thread.demo3; public class ObjectService {
private String uname;
private String pwd;
public void setUserNamePassWord(String userName,String passWord){
try {
String lock=new String();
synchronized (lock) {
System.out.println("thread name="+Thread.currentThread().getName()
+" 进入代码快:"+System.currentTimeMillis());
uname=userName;
Thread.sleep(3000);
pwd=passWord;
System.out.println("thread name="+Thread.currentThread().getName()
+" 进入代码快:"+System.currentTimeMillis()+"入参uname:"+uname+"入参pwd:"+pwd);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
运行结果:
结论:
多个线程持有对象监视器作为同一个对象的前提下,同一时间只有一个线程可以执行synchronized(任意自定义对象)同步代码快。
synchronized(任意自定义对象)与synchronized同步方法共用
- package com.zwz.thread.demo4;
- public class ObjectService {
- private String lock=new String();
- public void methodA(){
- try {
- synchronized (lock) {
- System.out.println("a begin");
- Thread.sleep(3000);
- System.out.println("a end");
- }
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- public synchronized void methodB(){
- System.out.println("b begin");
- System.out.println("b end");
- }
- }
package com.zwz.thread.demo4; public class ObjectService {
private String lock=new String();
public void methodA(){
try {
synchronized (lock) {
System.out.println("a begin");
Thread.sleep(3000);
System.out.println("a end");
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public synchronized void methodB(){
System.out.println("b begin");
System.out.println("b end");
}
}
- package com.zwz.thread.demo4;
- public class ThreadA extends Thread {
- private ObjectService objectService;
- public ThreadA(ObjectService objectService) {
- super();
- this.objectService = objectService;
- }
- @Override
- public void run() {
- objectService.methodA();
- }
- }
package com.zwz.thread.demo4; public class ThreadA extends Thread {
private ObjectService objectService; public ThreadA(ObjectService objectService) {
super();
this.objectService = objectService;
}
@Override
public void run() {
objectService.methodA();
}
}
- package com.zwz.thread.demo4;
- public class ThreadB extends Thread {
- private ObjectService objectService;
- public ThreadB(ObjectService objectService) {
- super();
- this.objectService = objectService;
- }
- @Override
- public void run() {
- objectService.methodB();
- }
- }
package com.zwz.thread.demo4; public class ThreadB extends Thread {
private ObjectService objectService; public ThreadB(ObjectService objectService) {
super();
this.objectService = objectService;
}
@Override
public void run() {
objectService.methodB();
}
}
- package com.zwz.thread.demo4;
- public class MainTest {
- public static void main(String[] args) {
- ObjectService service=new ObjectService();
- ThreadA a=new ThreadA(service);
- a.setName("A");
- a.start();
- ThreadB b=new ThreadB(service);
- b.setName("B");
- b.start();
- }
- }
package com.zwz.thread.demo4; public class MainTest {
public static void main(String[] args) {
ObjectService service=new ObjectService();
ThreadA a=new ThreadA(service);
a.setName("A");
a.start();
ThreadB b=new ThreadB(service);
b.setName("B");
b.start();
} }
运行结果:
结论:
使用synchronized(任意自定义对象)进行同步操作,对象监视器必须是同一个对象。不过不是同一个,运行就是异步执行了。
静态同步synchronized方法与synchronized(*.class)代码块
静态同步synchronized方法
- package com.zwz.thread.demo6;
- public class ObjectService {
- public synchronized static void methodA(){
- try {
- System.out.println("static methodA begin 线程名称:"+Thread.currentThread().getName()+" times:"+System.currentTimeMillis());
- Thread.sleep(3000);
- System.out.println("static methodA end 线程名称:"+Thread.currentThread().getName()+" times:"+System.currentTimeMillis());
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- public synchronized static void methodB(){
- System.out.println("static methodB begin 线程名称:"+Thread.currentThread().getName()+" times:"+System.currentTimeMillis());
- System.out.println("static methodB end 线程名称:"+Thread.currentThread().getName()+" times:"+System.currentTimeMillis());
- }
- }
package com.zwz.thread.demo6; public class ObjectService {
public synchronized static void methodA(){
try {
System.out.println("static methodA begin 线程名称:"+Thread.currentThread().getName()+" times:"+System.currentTimeMillis());
Thread.sleep(3000);
System.out.println("static methodA end 线程名称:"+Thread.currentThread().getName()+" times:"+System.currentTimeMillis());
} catch (InterruptedException e) {
e.printStackTrace();
}
} public synchronized static void methodB(){
System.out.println("static methodB begin 线程名称:"+Thread.currentThread().getName()+" times:"+System.currentTimeMillis());
System.out.println("static methodB end 线程名称:"+Thread.currentThread().getName()+" times:"+System.currentTimeMillis());
}
}
- package com.zwz.thread.demo6;
- public class ThreadA extends Thread {
- @Override
- public void run() {
- ObjectService.methodA();
- }
- }
package com.zwz.thread.demo6; public class ThreadA extends Thread { @Override
public void run() {
ObjectService.methodA();
}
}
- package com.zwz.thread.demo6;
- public class ThreadB extends Thread {
- @Override
- public void run() {
- ObjectService.methodB();
- }
- }
package com.zwz.thread.demo6; public class ThreadB extends Thread {
@Override
public void run() {
ObjectService.methodB();
}
}
- package com.zwz.thread.demo6;
- public class MainTest {
- public static void main(String[] args) {
- ThreadA a=new ThreadA();
- a.setName("A");
- a.start();
- ThreadB b=new ThreadB();
- b.setName("B");
- b.start();
- }
- }
package com.zwz.thread.demo6; public class MainTest {
public static void main(String[] args) {
ThreadA a=new ThreadA();
a.setName("A");
a.start();
ThreadB b=new ThreadB();
b.setName("B");
b.start();
}
}
运行结果:
synchronized(*.class)代码块
- package com.zwz.thread.demo7;
- public class ObjectService {
- public void methodA(){
- try {
- synchronized (ObjectService.class) {
- System.out.println("methodA begin 线程名称:"+Thread.currentThread().getName()+" times:"+System.currentTimeMillis());
- Thread.sleep(3000);
- System.out.println("methodA end 线程名称:"+Thread.currentThread().getName()+" times:"+System.currentTimeMillis());
- }
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- public void methodB(){
- synchronized (ObjectService.class) {
- System.out.println("methodB begin 线程名称:"+Thread.currentThread().getName()+" times:"+System.currentTimeMillis());
- System.out.println("methodB end 线程名称:"+Thread.currentThread().getName()+" times:"+System.currentTimeMillis());
- }
- }
- }
package com.zwz.thread.demo7; public class ObjectService {
public void methodA(){
try {
synchronized (ObjectService.class) {
System.out.println("methodA begin 线程名称:"+Thread.currentThread().getName()+" times:"+System.currentTimeMillis());
Thread.sleep(3000);
System.out.println("methodA end 线程名称:"+Thread.currentThread().getName()+" times:"+System.currentTimeMillis());
}
} catch (InterruptedException e) {
e.printStackTrace();
}
} public void methodB(){
synchronized (ObjectService.class) {
System.out.println("methodB begin 线程名称:"+Thread.currentThread().getName()+" times:"+System.currentTimeMillis());
System.out.println("methodB end 线程名称:"+Thread.currentThread().getName()+" times:"+System.currentTimeMillis());
}
}
}
- package com.zwz.thread.demo7;
- public class ThreadA extends Thread {
- private ObjectService objectService;
- public ThreadA(ObjectService objectService) {
- super();
- this.objectService = objectService;
- }
- @Override
- public void run() {
- objectService.methodA();
- }
- }
package com.zwz.thread.demo7; public class ThreadA extends Thread {
private ObjectService objectService; public ThreadA(ObjectService objectService) {
super();
this.objectService = objectService;
}
@Override
public void run() {
objectService.methodA();
}
}
- package com.zwz.thread.demo7;
- public class ThreadB extends Thread {
- private ObjectService objectService;
- public ThreadB(ObjectService objectService) {
- super();
- this.objectService = objectService;
- }
- @Override
- public void run() {
- objectService.methodB();
- }
- }
package com.zwz.thread.demo7; public class ThreadB extends Thread {
private ObjectService objectService; public ThreadB(ObjectService objectService) {
super();
this.objectService = objectService;
}
@Override
public void run() {
objectService.methodB();
}
}
- package com.zwz.thread.demo7;
- public class MainTest {
- public static void main(String[] args) {
- ObjectService service=new ObjectService();
- ThreadA a=new ThreadA(service);
- a.setName("A");
- a.start();
- ThreadB b=new ThreadB(service);
- b.setName("B");
- b.start();
- }
- }
package com.zwz.thread.demo7; public class MainTest {
public static void main(String[] args) {
ObjectService service=new ObjectService();
ThreadA a=new ThreadA(service);
a.setName("A");
a.start();
ThreadB b=new ThreadB(service);
b.setName("B");
b.start();
}
}
运行结果:
- package com.zwz.thread.demo7;
- public class MainTest {
- public static void main(String[] args) {
- ObjectService service1=new ObjectService();
- ObjectService service2=new ObjectService();
- ThreadA a=new ThreadA(service1);
- a.setName("A");
- a.start();
- ThreadB b=new ThreadB(service2);
- b.setName("B");
- b.start();
- }
- }
package com.zwz.thread.demo7; public class MainTest {
public static void main(String[] args) {
ObjectService service1=new ObjectService();
ObjectService service2=new ObjectService();
ThreadA a=new ThreadA(service1);
a.setName("A");
a.start();
ThreadB b=new ThreadB(service2);
b.setName("B");
b.start();
}
}
运行结果:
synchronized(this)、synchronized(class)与synchronized(Object)的区别的更多相关文章
- java 多线程 Synchronized方法和方法块 synchronized(this)和synchronized(object)的理解
synchronized 关键字,它包括两种用法:synchronized 方法和 synchronized 块. 1. synchronized 方法:通过在方法声明中加入 synchronized ...
- Lock、synchronized和ReadWriteLock,StampedLock戳锁的区别和联系以及Condition
https://www.cnblogs.com/RunForLove/p/5543545.html 先来看一段代码,实现如下打印效果: 1 2 A 3 4 B 5 6 C 7 8 D 9 10 E 1 ...
- java-测试synchronized使用xxx.class和this使用的区别
synchronized测试1 写两个线程调用同一个方法,在其中分别做一个class和this的调用,看结果 1.xx.class public class Test{ public static v ...
- 使用synchronized修饰静态方法和非静态方法有什么区别
前言 最近被问到了这个问题,第一次回答的也是很不好,在此参考网上答案进行整理记录.供大家学习参考. Synchronized修饰非静态方法 Synchronized修饰非静态方法,实际上是对调用该方法 ...
- Python中type与Object的区别
Python中type与Object的区别 在查看了Python的API后,总算明白了.现在总结如下: 先来看object的说明: Python中关于object的说明很少,甚至只有一句话: clas ...
- Java不定参数Object… obj 和 Object[] 的区别
Java不定参数Object… obj 和 Object[] 的区别 简述: java中方法重载可以实现参数不同自动匹配对应方法.但现实中也存在这种问题.普通传参对于形如下面的方法,却显得臃肿而失优雅 ...
- 新手向-同步关键字synchronized对this、class、object、方法的区别
synchronized的语义 实验 分析 在看源代码时遇到多线程需要同步的时候,总是会看见几种写法,修饰方法.修饰静态方法.synchronized(Xxx.class).synchronized( ...
- map泛型 map不指定泛型 与 Map<Object,Object>的区别
map泛型 map不指定泛型 与 Map<Object,Object>的区别 private void viewDetail(){ Map map1 = new HashMap(); Ma ...
- Java的synchronized的同步代码块和同步方法的区别
synchronized同步方法和同步代码块的区别 同步方法默认使用this或者当前类做为锁. 同步代码块可以选择以什么来加锁,比同步方法更精确,我们可以选择只有会在同步发生同步问题的代码加锁,而并不 ...
随机推荐
- 洛谷 P3616 富金森林公园题解(树状数组)
P3616 富金森林公园 题目描述 博艾的富金森林公园里有一个长长的富金山脉,山脉是由一块块巨石并列构成的,编号从1到N.每一个巨石有一个海拔高度.而这个山脉又在一个盆地中,盆地里可能会积水,积水也有 ...
- LOJ6503. 「雅礼集训 2018 Day4」Magic(容斥原理+NTT)
题目链接 https://loj.ac/problem/6503 题解 题中要求本质不同的序列数量,不太好搞.我们考虑给相同颜色的牌加上编号,这样所有牌都不相同.那么如果我们求出了答案,只需要将答案除 ...
- Carryon 数数字
Carryon 数数字 描述 Carryon 最近迷上了数数字,然后 Starry 给了他一个区间[l,r] ,然后提了几个要求, 需要将 l 到 r 之间的数全部转化成 16 进制,然后连起来. 将 ...
- 【总结】sqlmap-tamper编写小结
目的:修改sqlmap中的tamper脚本来绕过代码对特定参数的过滤和转义 环境:win10.phpstudy2016.sqli-labs-master平台 工具:sqlmap.burpsuite 地 ...
- superobject 设定排序方式
(* * Super Object Toolkit * * Usage allowed under the restrictions of the Lesser GNU General Public ...
- Ionic3,安装,创建项目(一)
Ionic3 简介:是一款html5的轻量级手机开发框架,基于angularjs.scss语法,ionic是一个轻量的手机UI库.并直接放弃了IOS 6和Android 4.1一下的版本支持. 安装: ...
- PIXI 太空玉兔游戏(6)
想法来源 出于练习看到这篇文章 没有什么难度 效果如下,接下来会用pixijs讲解如何实现 创建应用及舞台 HTML部分只创建标签引入 pixi.min.js 即可: <script ...
- 4.显式锁 Lock
4.1 概念 内置锁 vs 显示锁 synchronize是java语言层面实现的锁,称为内置锁.使用方便代码简洁,而且在jdk新版本优化后,性能也得到了很大的提高.synchronize是一个可重入 ...
- Bloom filter和Counting bloom filter
Bloom filter原理: https://en.wikipedia.org/wiki/Bloom_filter 推导过程结合博客: https://blog.csdn.net/jiaomeng/ ...
- 抱歉最近朋友结婚去浪了几天~未来几天会正常更新.今天带来XML文件解析
三种解析方法 DOM,SAX,XMLPullParse;你以为我要讲三种嘛 错 ,我只讲一种 ,其他两种我只是说下优缺点, 一.DOM解析器 优点: DOM解析器在解析XML文档时,会把文档中的所有元 ...