DemoFindFile.java
/*
* Copyright 2024 Hochschule Luzern Informatik.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.hslu.exercises.sw11.ex4.findfile;
import java.io.File;
import java.time.Duration;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
/**
* Codevorlage für eine Dateisuche.
*/
public final class DemoFindFile {
private static final Logger LOG = LoggerFactory.getLogger(DemoFindFile.class);
/**
* Privater Konstruktor.
*/
private DemoFindFile() {
}
/**
* Main-Demo.
*
* @param args not used.
*/
public static void main(final String[] args) throws ExecutionException, InterruptedException {
long start;
long stop;
Duration duration;
final String search = "CNA-Labor1_-_Firewall_Basics.pdf";
final File rootDir = new File(System.getProperty("user.home"));
LOG.info("Start searching '{}' recurive in '{}'", search, rootDir);
start = System.currentTimeMillis();
// FindFile.findFile(search, rootDir);
stop = System.currentTimeMillis();
duration = Duration.ofMillis(stop - start);
LOG.info("Found in {} msec.", duration.toMillis());
LOG.info("Find '{}' concurrent in '{}'", search, rootDir);
final FindFileTask root = new FindFileTask(search, rootDir);
start = System.currentTimeMillis();
LOG.info(root.invoke());
stop = System.currentTimeMillis();
duration = Duration.ofMillis(stop - start);
LOG.info("Found in {} msec.", duration.toMillis());
final ExecutorService executor = Executors.newSingleThreadExecutor();
final MaximumNew max = new MaximumNew();
Future<Integer> submit = executor.submit(max);
int maxV = submit.get();
}
}