相关疑难解决方法(0)

Java性能测量

我正在我的类之间进行一些Java性能比较,并想知道是否有某种Java性能框架可以使编写性能测量代码更容易?

也就是说,我现在正在尝试测量的是,与使用AtomicInteger作为我的"同步器"相比,PseudoRandomUsingSynch.nextInt()中的方法具有"同步"的效果.

因此,我试图测量使用3个线程访问同步方法循环10000次的生成随机整数所需的时间.

我相信有更好的方法可以做到这一点.能请你赐教吗?:)

public static void main( String [] args ) throws InterruptedException, ExecutionException {
    PseudoRandomUsingSynch rand1 = new PseudoRandomUsingSynch((int)System.currentTimeMillis());
    int n = 3;
    ExecutorService execService = Executors.newFixedThreadPool(n);

    long timeBefore = System.currentTimeMillis();
    for(int idx=0; idx<100000; ++idx) {
        Future<Integer> future = execService.submit(rand1);
        Future<Integer> future1 = execService.submit(rand1);
        Future<Integer> future2 = execService.submit(rand1);

        int random1 = future.get();
        int random2 = future1.get();
        int random3 = future2.get();

    }
    long timeAfter = System.currentTimeMillis();
    long elapsed = timeAfter - timeBefore;
    out.println("elapsed:" + elapsed);
}
Run Code Online (Sandbox Code Playgroud)

班级

public class …
Run Code Online (Sandbox Code Playgroud)

java performance multithreading

13
推荐指数
4
解决办法
2万
查看次数

get(int index)和elementAt(int index)之间有什么区别?

Vector有两种方法可以在一个索引处获取元素.

Vector<Integer> matrix;
matrix = new Vector<Integer>;
matrix.get(0);
matrix.elementAt(0);
Run Code Online (Sandbox Code Playgroud)

看来他们在这里也做同样的事情.

java collections vector

-1
推荐指数
2
解决办法
3196
查看次数

标签 统计

java ×2

collections ×1

multithreading ×1

performance ×1

vector ×1