小编Pet*_*ter的帖子

VisualVM运行JRE

我不能让VisualVM使用eclipse,我遵循这些说明 http://visualvm.java.net/download.html 以及这些 http://visualvm.java.net/gettingstarted.html

问题是它无法看到JDK位置是"C:\ Program Files\Java\jdk1.8.0_05",当我尝试运行应用程序时会发生这种情况

在此输入图像描述

这是visualvm.conf文件的原始内容

http://pastebin.com/K9TnQb0G

不幸的是我的命令行也不知何故(或者我不知道该怎么做)

在此输入图像描述

首先我尝试安装JProbe但它没有工作,然后我尝试了VisualVM,它也无法正常工作.我该如何解决这个问题?我浪费了5个小时,它让我疯狂.

java eclipse visualvm

6
推荐指数
3
解决办法
1万
查看次数

HashSet 和 TreeSet 性能测试

我读到了 TreeSet 比 HashSet 慢的原因(将元素添加到 TreeSet 中更慢)所以我进行了性能测试,我试图找出将元素添加到 HashSet 然后将它们移动到 TreeSet 或首先把它们放在那里。看起来将元素插入 HashSet 更快,但只有当我插入大量元素时,为什么?我读过,如果我不需要对元素进行排序,请始终使用 HashSet,但显然,有时它会更慢。

当我插入一个具体的值(“1”)而不是随机数时,TreeSet 也更快,因为没有排序,那么我怎么知道什么时候使用 HashSet 或 TreeSet?

我的第二个问题,当我像这样创建 TreeSet 时,为什么我不能访问“NavigableSet”方法?

Set<Integer> treeSet = new TreeSet<Integer>();     //cant type treeSet.lower(e: E)
TreeSet<Integer> treeSet = new TreeSet<Integer>(); //can  type treeSet.lower(e: E)
Run Code Online (Sandbox Code Playgroud)

谢谢你帮我解决这个问题。

结果如下:

5 000 000(随机数)

在此处输入图片说明

5 000 000(数字“1”)

在此处输入图片说明

500 000(随机数)

在此处输入图片说明

50 000(随机数)

在此处输入图片说明

这是我的代码:

package performancetest;

import java.text.DecimalFormat;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.Scanner;
import java.util.TreeSet;

public class HashSet_vs_TreeSet {
private static DecimalFormat df = new DecimalFormat("#.#####");
private static double hashTime, …
Run Code Online (Sandbox Code Playgroud)

java performance hashset treeset

5
推荐指数
1
解决办法
3711
查看次数

线程池性能

我试图了解使用线程池的优势,我编写此代码以查看固定线程池的时间改进.

首先,我将池中的线程数设置为1,花了大约920毫秒,然后我将池中的线程数更改为2(和3,4,5,6,7 ...) 1200毫秒,当线程同时运行时,它不应该更快吗?

当我将其更改为缓存的线程池时,它也需要1200毫秒

package threadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Example3 {

public static void main(String[] args) {

    new Example3();

}

public Example3() {

    try {
        testFixedPool(1);
      //testFixedPool(2);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

}

public void testFixedPool(int numberOfThreads) throws InterruptedException {

    ExecutorService executor = Executors.newFixedThreadPool(numberOfThreads);

    long start = System.currentTimeMillis();

    executor.execute(new TaskPrintInteger(0, 10000));
    executor.execute(new TaskPrintInteger(1, 10000));
    executor.execute(new TaskPrintInteger(2, 10000));
    executor.execute(new TaskPrintInteger(3, 10000));
    executor.execute(new TaskPrintInteger(4, 10000));
    executor.execute(new TaskPrintInteger(5, 10000));
    executor.execute(new TaskPrintInteger(6, 10000));
    executor.execute(new TaskPrintInteger(7, 10000));
    executor.execute(new TaskPrintInteger(8, …
Run Code Online (Sandbox Code Playgroud)

java multithreading performance-testing threadpool

4
推荐指数
1
解决办法
1696
查看次数