Skip to content

Commit 2f362d9

Browse files
committed
新增:线程相关
1 parent 4a56973 commit 2f362d9

2 files changed

Lines changed: 79 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package org.javacore.thread; /*
2+
* Copyright [2015] [Jeff Lee]
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import java.io.IOException;
18+
import java.util.Scanner;
19+
20+
/**
21+
* Java进程调用CMD
22+
* VM options => -Dfile.encoding="GBK"
23+
* @author BYSocket
24+
* @since 2016-01-18 16:08:00
25+
*/
26+
public class ProcessBuilderTest {
27+
public static void main(String[] args) throws IOException {
28+
ProcessBuilder pb = new ProcessBuilder("cmd","/c","ipconfig/all");
29+
Process p = pb.start();
30+
31+
Scanner scanner = new Scanner(p.getInputStream());
32+
while (scanner.hasNext())
33+
System.out.println(scanner.next());
34+
scanner.close();
35+
}
36+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package org.javacore.thread; /*
2+
* Copyright [2015] [Jeff Lee]
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* Thread中start和run的区别
19+
* @author BYSocket
20+
* @since 2016-01-18 15:55:00
21+
*/
22+
public class SleepRunThread {
23+
public static void main(String[] args) {
24+
System.out.println("当前线程ID => " + Thread.currentThread().getId());
25+
26+
SRThread t1 = new SRThread("t1");
27+
t1.start();
28+
SRThread t2 = new SRThread("t2");
29+
t2.run();
30+
}
31+
}
32+
class SRThread extends Thread {
33+
private String name;
34+
35+
public SRThread(String name) {
36+
this.name = name;
37+
}
38+
39+
@Override
40+
public void run() {
41+
System.out.println("name:" + name +", 线程ID => " + Thread.currentThread().getId());
42+
}
43+
}

0 commit comments

Comments
 (0)