我正在编写一个小型Java应用程序来分析大量的图像文件.现在,它通过平均图像中每个像素的亮度并将其与文件夹中的其他图像进行比较,找到文件夹中最亮的图像.
有时,我在启动后立即获得100+图像/秒的速率,但这几乎总是下降到<20图像/秒,我不知道为什么.当它处于100+图像/秒时,CPU使用率为100%,但随后降至20%左右,这似乎太低了.
这是主要课程:
public class ImageAnalysis {
public static final ConcurrentLinkedQueue<File> queue = new ConcurrentLinkedQueue<>();
private static final ConcurrentLinkedQueue<ImageResult> results = new ConcurrentLinkedQueue<>();
private static int size;
private static AtomicInteger running = new AtomicInteger();
private static AtomicInteger completed = new AtomicInteger();
private static long lastPrint = 0;
private static int completedAtLastPrint;
public static void main(String[] args){
File rio = new File(IO.CAPTURES_DIRECTORY.getAbsolutePath() + File.separator + "Rio de Janeiro");
String month = "12";
Collections.addAll(queue, rio.listFiles((dir, name) -> {
return (name.substring(0, 2).equals(month));
})); …Run Code Online (Sandbox Code Playgroud) 我有一个 Kotlin 数据类,我正在使用许多不可变属性构建它,这些属性是从单独的 SQL 查询中获取的。如果我想使用构建器模式构造数据类,如何在不使这些属性可变的情况下执行此操作?
例如,而不是通过构建
var data = MyData(val1, val2, val3)
Run Code Online (Sandbox Code Playgroud)
我想用
builder.someVal(val1)
// compute val2
builder.someOtherVal(val2)
// ...
var data = builder.build()
Run Code Online (Sandbox Code Playgroud)
同时仍然使用 Kotlin 的数据类功能和不可变属性。