Skip to content

Commit 8b75ae3

Browse files
authored
Merge pull request #1 from JavaCourse00/main
合并源码
2 parents bf86c46 + f3f6632 commit 8b75ae3

7 files changed

Lines changed: 43 additions & 33 deletions

File tree

02nio/nio01/src/main/java/java0/nio01/netty/NettyHttpServer.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ public static void main(String[] args) throws InterruptedException {
2222
try {
2323
ServerBootstrap b = new ServerBootstrap();
2424
b.option(ChannelOption.SO_BACKLOG, 128)
25-
.option(ChannelOption.TCP_NODELAY, true)
26-
.option(ChannelOption.SO_KEEPALIVE, true)
27-
.option(ChannelOption.SO_REUSEADDR, true)
28-
.option(ChannelOption.SO_RCVBUF, 32 * 1024)
29-
.option(ChannelOption.SO_SNDBUF, 32 * 1024)
30-
.option(EpollChannelOption.SO_REUSEPORT, true)
25+
.childOption(ChannelOption.TCP_NODELAY, true)
3126
.childOption(ChannelOption.SO_KEEPALIVE, true)
32-
.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
27+
.childOption(ChannelOption.SO_REUSEADDR, true)
28+
.childOption(ChannelOption.SO_RCVBUF, 32 * 1024)
29+
.childOption(ChannelOption.SO_SNDBUF, 32 * 1024)
30+
.childOption(EpollChannelOption.SO_REUSEPORT, true)
31+
.childOption(ChannelOption.SO_KEEPALIVE, true)
32+
.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
3333

3434
b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
3535
.handler(new LoggingHandler(LogLevel.INFO))

02nio/nio02/src/main/java/io/github/kimmking/gateway/inbound/HttpInboundServer.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ public void run() throws Exception {
3636
try {
3737
ServerBootstrap b = new ServerBootstrap();
3838
b.option(ChannelOption.SO_BACKLOG, 128)
39-
.option(ChannelOption.TCP_NODELAY, true)
40-
.option(ChannelOption.SO_KEEPALIVE, true)
41-
.option(ChannelOption.SO_REUSEADDR, true)
42-
.option(ChannelOption.SO_RCVBUF, 32 * 1024)
43-
.option(ChannelOption.SO_SNDBUF, 32 * 1024)
44-
.option(EpollChannelOption.SO_REUSEPORT, true)
39+
.childOption(ChannelOption.TCP_NODELAY, true)
4540
.childOption(ChannelOption.SO_KEEPALIVE, true)
46-
.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
41+
.childOption(ChannelOption.SO_REUSEADDR, true)
42+
.childOption(ChannelOption.SO_RCVBUF, 32 * 1024)
43+
.childOption(ChannelOption.SO_SNDBUF, 32 * 1024)
44+
.childOption(EpollChannelOption.SO_REUSEPORT, true)
45+
.childOption(ChannelOption.SO_KEEPALIVE, true)
46+
.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
4747

4848
b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
4949
.handler(new LoggingHandler(LogLevel.DEBUG))

03concurrency/0301/src/main/java/java0/conc0301/DaemonThread.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,22 @@
22

33
public class DaemonThread {
44

5-
public static void main(String[] args) {
6-
Runnable task = new Runnable() {
7-
@Override
8-
public void run() {
5+
public static void main(String[] args) throws InterruptedException {
6+
Runnable task = () -> {
97
try {
10-
Thread.sleep(5000);
11-
} catch (InterruptedException e) {
12-
e.printStackTrace();
13-
}
8+
Thread.sleep(1000);
9+
} catch (InterruptedException e) {
10+
e.printStackTrace();
11+
}
1412
Thread t = Thread.currentThread();
1513
System.out.println("当前线程:" + t.getName());
16-
}
1714
};
1815
Thread thread = new Thread(task);
1916
thread.setName("test-thread-1");
20-
thread.setDaemon(false);
17+
thread.setDaemon(true);
2118
thread.start();
19+
20+
//Thread.sleep(2000);
2221
}
2322

2423

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package java0.conc0301;
2+
3+
public class ThreadCount {
4+
public static void main(String[] args) throws InterruptedException {
5+
//System.out.println("system:"+Thread.currentThread().getThreadGroup().getParent());
6+
Thread.currentThread().getThreadGroup().getParent().list();
7+
8+
// System.out.println("main:"+Thread.currentThread().getThreadGroup());
9+
// Thread.currentThread().getThreadGroup().list();
10+
}
11+
}

03concurrency/0301/src/main/java/java0/conc0301/op/Join.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ public static void main(String[] args) {
66
Object oo = new Object();
77

88
MyThread thread1 = new MyThread("thread1 -- ");
9+
//oo = thread1;
910
thread1.setOo(oo);
1011
thread1.start();
1112

12-
synchronized (thread1) {
13+
synchronized (oo) { // 这里用oo或thread1/this
1314
for (int i = 0; i < 100; i++) {
1415
if (i == 20) {
1516
try {
16-
thread1.join();
17+
oo.wait(0);
18+
//thread1.join();
1719
} catch (InterruptedException e) {
1820
e.printStackTrace();
1921
}
@@ -40,7 +42,7 @@ public MyThread(String name) {
4042

4143
@Override
4244
public void run() {
43-
synchronized (this) {
45+
synchronized (oo) { // 这里用oo或this,效果不同
4446
for (int i = 0; i < 100; i++) {
4547
System.out.println(name + i);
4648
}

03concurrency/0301/src/main/java/java0/conc0301/sync/Counter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class Counter {
77
public static int B=10;
88

99
private volatile int sum = 0;
10-
public synchronized void incr() {
10+
public void incr() {
1111
sum=sum+1;
1212
}
1313
public int getSum() {

03concurrency/0301/src/main/java/java0/conc0302/threadpool/ExceptionDemo.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,20 @@ public static void main(String[] args) {
1111

1212
try {
1313
Future<Double> future = executorService.submit(() -> {
14-
int a = 1;
15-
return 10.0/(a-1);
14+
throw new RuntimeException("executorService.submit()");
1615
});
1716

1817
double b = future.get();
1918
System.out.println(b);
2019

2120
} catch (Exception ex) {
22-
System.out.println("catch execute");
21+
System.out.println("catch submit");
2322
ex.printStackTrace();
2423
}
2524

2625
try {
2726
executorService.execute(() -> {
28-
int a = 1;
29-
float b = 10/(a-1);
27+
throw new RuntimeException("executorService.execute()");
3028
});
3129
} catch (Exception ex) {
3230
System.out.println("catch execute");

0 commit comments

Comments
 (0)