File tree Expand file tree Collapse file tree 3 files changed +66
-0
lines changed
multithreading/src/com/itp/threads Expand file tree Collapse file tree 3 files changed +66
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .itp .threads ;
2
+
3
+ import java .util .concurrent .ExecutorService ;
4
+ import java .util .concurrent .Executors ;
5
+
6
+ public class ThreadPoolTest {
7
+
8
+ public static void main (String [] args ) {
9
+
10
+ ExecutorService service = Executors .newFixedThreadPool (4 );
11
+
12
+ //Callable
13
+ //service.submit(new Deposit())
14
+
15
+ }
16
+ }
Original file line number Diff line number Diff line change
1
+ /bin /
Original file line number Diff line number Diff line change
1
+ package com .itp .searcheng ;
2
+
3
+ import java .io .BufferedReader ;
4
+ import java .io .File ;
5
+ import java .io .FilenameFilter ;
6
+ import java .nio .file .Files ;
7
+ import java .nio .file .Paths ;
8
+
9
+ public class Application {
10
+
11
+ public static void main (String [] args ) {
12
+
13
+ if (args .length != 2 ) {
14
+ System .out .println ("Usage: java Application <searchDir> <searchString>" );
15
+ System .exit (1 );
16
+ } else {
17
+ // System.out.println(args[0]);
18
+ // System.out.println(args[1]);
19
+
20
+ // 1. Retrieve all java files from given directory.
21
+
22
+ File dir = new File (args [0 ]);
23
+ File [] files = dir .listFiles (new FilenameFilter () {
24
+ @ Override
25
+ public boolean accept (File arg0 , String fname ) {
26
+ return fname .endsWith (".java" );
27
+ }
28
+ });
29
+
30
+ // 2. Search given content in each and every file.
31
+ for (File file : files ) {
32
+ System .out .println ("Searching into " + file .getAbsolutePath ());
33
+ try (BufferedReader br = Files .newBufferedReader (Paths .get (file .getAbsolutePath ()))) {
34
+ String line = "" ;
35
+ int count = 1 ;
36
+ while ((line = br .readLine ()) != null ) {
37
+ if (line .indexOf (args [1 ]) >= 0 ) {
38
+ System .out .println (count +":" +line );
39
+ }
40
+ count ++;
41
+ }
42
+ } catch (Exception e ) {
43
+ e .printStackTrace ();
44
+ }
45
+ }
46
+ }
47
+
48
+ }
49
+ }
You can’t perform that action at this time.
0 commit comments