View Javadoc
1   /*
2    * Copyright 2024 Hochschule Luzern Informatik.
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  package ch.hslu.exercises.sw11.ex4.findfile;
17  
18  import java.io.File;
19  import java.time.Duration;
20  import java.util.concurrent.ExecutionException;
21  import java.util.concurrent.ExecutorService;
22  import java.util.concurrent.Executors;
23  import java.util.concurrent.Future;
24  
25  import org.slf4j.LoggerFactory;
26  import org.slf4j.Logger;
27  
28  /**
29   * Codevorlage für eine Dateisuche.
30   */
31  public final class DemoFindFile {
32  
33      private static final Logger LOG = LoggerFactory.getLogger(DemoFindFile.class);
34  
35      /**
36       * Privater Konstruktor.
37       */
38      private DemoFindFile() {
39      }
40  
41      /**
42       * Main-Demo.
43       *
44       * @param args not used.
45       */
46      public static void main(final String[] args) throws ExecutionException, InterruptedException {
47          long start;
48          long stop;
49          Duration duration;
50          final String search = "CNA-Labor1_-_Firewall_Basics.pdf";
51          final File rootDir = new File(System.getProperty("user.home"));
52          LOG.info("Start searching '{}' recurive in '{}'", search, rootDir);
53          start = System.currentTimeMillis();
54  //        FindFile.findFile(search, rootDir);
55          stop = System.currentTimeMillis();
56          duration = Duration.ofMillis(stop - start);
57          LOG.info("Found in {} msec.", duration.toMillis());
58          LOG.info("Find '{}' concurrent in '{}'", search, rootDir);
59          final FindFileTask root = new FindFileTask(search, rootDir);
60          start = System.currentTimeMillis();
61          LOG.info(root.invoke());
62          stop = System.currentTimeMillis();
63          duration = Duration.ofMillis(stop - start);
64          LOG.info("Found in {} msec.", duration.toMillis());
65          final ExecutorService executor = Executors.newSingleThreadExecutor();
66          final MaximumNew max = new MaximumNew();
67          Future<Integer> submit = executor.submit(max);
68          int maxV = submit.get();
69      }
70  }