小编p2k*_*2kr的帖子

如何限制创建的线程数并等待主线程直到任何一个线程找到答案?

这是查找 LCM 和 HCF 之和等于该数字的第一对数字(1 除外)的代码。

import java.util.*;
import java.util.concurrent.atomic.AtomicLong;

class PerfectPartition {
    static long gcd(long a, long b) {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }

    // method to return LCM of two numbers
    static long lcm(long a, long b) {
        return (a / gcd(a, b)) * b;
    }

    long[] getPartition(long n) {
        var ref = new Object() {
            long x;
            long y;
            long[] ret = null;
        };

        Thread mainThread = Thread.currentThread();
        ThreadGroup t …
Run Code Online (Sandbox Code Playgroud)

java parallel-processing performance multithreading java-threads

8
推荐指数
1
解决办法
226
查看次数