File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments