File tree Expand file tree Collapse file tree 7 files changed +139
-35
lines changed
Expand file tree Collapse file tree 7 files changed +139
-35
lines changed Original file line number Diff line number Diff line change 1+ package com .chen .api .util .Integer ;
2+
3+ /**
4+ * 关于Integer比较大小的问题(http://www.blogjava.net/zhangyuan/archive/2010/07/24/327011.html)
5+ *
6+ * @author Chen WeiJie
7+ * @date 2018-01-17 15:55
8+ **/
9+ public class Test {
10+
11+
12+ @ org .junit .Test
13+ public void test () {
14+
15+ Integer a = 10 ;
16+ Integer b = 10 ;
17+ System .out .println ("a==b : " + String .valueOf (a == b ));
18+ System .out .println ("a.equals(b) : " + String .valueOf (a .equals (b )));
19+
20+ }
21+
22+
23+ @ org .junit .Test
24+ public void test2 () {
25+
26+ Integer a = 1000 ;
27+ Integer b = 1000 ;
28+ System .out .println ("a==b : " + String .valueOf (a == b ));
29+ System .out .println ("a.equals(b) : " + String .valueOf (a .equals (b )));
30+
31+ }
32+
33+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ public class MyThread extends Thread {
1111
1212 @ Override
1313 public void run (){
14- System .out .println (Thread .currentThread ().getName ()+ "正在运行。。。" );
14+ System .out .println (Thread .currentThread ().getName () + "正在运行。。。" );
1515 }
1616
1717}
Original file line number Diff line number Diff line change 1+ package com .chen .api .util .thread .threadPool ;
2+
3+ import java .util .concurrent .ExecutorService ;
4+ import java .util .concurrent .Executors ;
5+
6+ /**
7+ * 可缓存线程池,当线程池大小超过了处理任务所需的线程,那么就会回收部分空闲(一般是60秒无执行)的线程,当有任务来时,又智能的添加新线程来执行。
8+ *
9+ * @author Chen WeiJie
10+ * @date 2018-04-03 17:28
11+ **/
12+ public class NewCacheThreadExecutor {
13+
14+ public static void main (String [] args ) {
15+
16+ //创建一个可重用固定线程数的线程池
17+ ExecutorService pool = Executors .newCachedThreadPool ();
18+ //创建实现了Runnable接口对象
19+ Thread t1 = new MyThread ();
20+ Thread t2 = new MyThread ();
21+ Thread t3 = new MyThread ();
22+ Thread t4 = new MyThread ();
23+ Thread t5 = new MyThread ();
24+ //将线程放入池中进行执行
25+ pool .execute (t1 );
26+ pool .execute (t2 );
27+ pool .execute (t3 );
28+ pool .execute (t4 );
29+ pool .execute (t5 );
30+ //关闭线程池
31+ pool .shutdown ();
32+
33+ }
34+ }
Original file line number Diff line number Diff line change 1+ package com .chen .api .util .thread .threadPool ;
2+
3+ import java .util .concurrent .ExecutorService ;
4+ import java .util .concurrent .Executors ;
5+
6+ /**
7+ * 单个线程的线程池,单线程串行执行任务
8+ *
9+ * @author Chen WeiJie
10+ * @date 2018-04-03 16:58
11+ **/
12+ public class NewSingleThreadExecutor {
13+
14+ public static void main (String [] args ) {
15+
16+ ExecutorService pool = Executors .newSingleThreadExecutor ();
17+
18+ MyThread t1 = new MyThread ();
19+ MyThread t2 = new MyThread ();
20+ MyThread t3 = new MyThread ();
21+ MyThread t4 = new MyThread ();
22+ pool .execute (t1 );
23+ pool .execute (t2 );
24+ pool .execute (t3 );
25+ pool .execute (t4 );
26+ pool .shutdown ();
27+
28+ }
29+ }
Original file line number Diff line number Diff line change 1+ package com .chen .util ;
2+
3+ /**
4+ * 位运算例子
5+ *
6+ * @author Chen WeiJie
7+ * @date 2018-03-23 14:58
8+ **/
9+ public class BitCalc {
10+
11+ public static void main (String [] args ) {
12+
13+ int a = 60 ; /* 60 = 0011 1100 */
14+ int b = 13 ; /* 13 = 0000 1101 */
15+ int c = 0 ;
16+ c = a & b ; /* 12 = 0000 1100 */
17+ System .out .println ("a & b = " + c );
18+
19+ c = a | b ; /* 61 = 0011 1101 */
20+ System .out .println ("a | b = " + c );
21+
22+ c = a ^ b ; /* 49 = 0011 0001 */
23+ System .out .println ("a ^ b = " + c );
24+
25+ c = ~a ; /*-61 = 1100 0011 */
26+ System .out .println ("~a = " + c );
27+
28+ c = a << 2 ; /* 240 = 1111 0000 */
29+ System .out .println ("a << 2 = " + c );
30+
31+ c = a >> 2 ; /* 15 = 1111 */
32+ System .out .println ("a >> 2 = " + c );
33+
34+ c = a >>> 2 ; /* 15 = 0000 1111 */
35+ System .out .println ("a >>> 2 = " + c );
36+ }
37+ }
Original file line number Diff line number Diff line change @@ -21,6 +21,11 @@ public static void main(String[] args) {
2121 System .out .println (index4 );
2222 System .out .println (index5 );
2323
24+ String index6 = String .format ("%01d" , 10025 % 10 );
25+ System .out .println (index6 );
26+ double l =Math .pow (10 ,6 );
27+ System .out .println (l );
28+
2429 }
2530
2631}
You can’t perform that action at this time.
0 commit comments