小编Gwi*_*lym的帖子

Java RMI AccessControlException:访问被拒绝

嘿我AccessControlException: access denied在尝试启动我正在编写的RMI应用程序时遇到了问题,如果我在默认端口1099上打开它,或者在另一个动态端口,我的策略文件当前打开它,我无法理解为什么会出现此异常授予一切(在应用完成后会改变).

我被困在哪里出错了,任何帮助都会很有用

我的代码

public class Main {

/**
 * @param args the command line arguments
 */
public static void main(String[] args) throws RemoteException, AlreadyBoundException, MalformedURLException {
     if (System.getSecurityManager() == null)
     {
        System.setSecurityManager ( new RMISecurityManager() );
     }

     CreditCardServer ccs = new CreditCardServer();

     int port = 1099;

     try {
        port = Integer.valueOf(args[0]);
        }
     catch (Exception e)
        {
        System.out.println("Invlaid Port");
        }

     if (((port <= 65535) && (port >= 49152)) || port ==1099)
     {
     System.out.println("Valid Port");
     }
     else
     { …
Run Code Online (Sandbox Code Playgroud)

java rmi accesscontrolexception

19
推荐指数
2
解决办法
6万
查看次数

非多线程程序中的java.util.ConcurrentModificationException

嘿SO Guru,我对这段代码有一点工作

public void kill(double GrowthRate, int Death)
{
    int before = population.size();
    for (PopulationMember p : population)
    {
        int[] probs = ProbablityArrayDeath(GrowthRate,Death,(int)p.fitness());
        if (probs[RandomNumberGen.nextRandomInt(0, 99)]==0)
        {
            population.remove(p);
        }
    }
    System.out.println("Intial Population: "+before+", Deaths:"+(before-          population.size())+", New Population: "+population.size());
}
Run Code Online (Sandbox Code Playgroud)

当我第一次尝试运行代码时运行我的程序时,它会遇到此错误

Exception in thread "main" java.util.ConcurrentModificationException
    at java.util.HashMap$HashIterator.nextEntry(HashMap.java:793)
    at java.util.HashMap$KeyIterator.next(HashMap.java:828)
    at Genetics.Population.kill(Population.java:181)
    at Genetics.Population.run(Population.java:47)
    at Control.Main.main(Main.java:35)
Run Code Online (Sandbox Code Playgroud)

稍微晃了一下这似乎是一个错误,通常会发生在线程为什么他们尝试同时访问相同的资源,但这就是让我在这个系统中完全没有多线程的原因.

有人可以解释为什么会这样,或者想到一个黑客来解决它

非常感谢^ _ ^

java collections multithreading java.util.concurrent

15
推荐指数
3
解决办法
2万
查看次数

C++新手,帮助我入门

我是一名Java程序员,有一点C知识谁想要开始使用C++,有人可以推荐一个好的教程吗?

也有任何帮助:

  • 要学习的项目
  • 推荐阅读
  • 什么IDE?我目前使用NetBeans
  • 一般的C++建议

c++ ide

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

Java - 检查文件是否在打印队列/正在使用中

好的我有一个程序:

  1. 根据用户输入创建临时文件
  2. 打印文件(可选)
  3. 删除文件(可选)

我的问题在第2和第3阶段之间,我需要等待文件完成打印,直到我可以删除它.

仅供参考:打印需要5-10分钟(在旧计算机上打印大文件)

所以我需要从Java能够检查是否:

  • defualt打印队列是空的

  • 文件正在使用中(注意:File.canWrite()在打印时返回true)

java printing locking file

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

不确定ConcurrentModificationException的原因

这是我的代码,用于构建一个可能的城市之旅Locale l(这不是最佳的,只是为了让我的AI搜索起步).

我得到了一个ConcurrentModificationException,据我所知,当多个代码访问变量/集合并尝试修改它时.导致此代码变得不快乐:

final void checkForComodification() {
    if (modCount != expectedModCount)
        throw new ConcurrentModificationException();
}
Run Code Online (Sandbox Code Playgroud)

我修改它,因为我正在添加一个元素,但由于Iterator没有添加(仅删除)的方法,我正在使用集合的方法.

所以,我的问题是:

  1. 我添加元素是什么导致问题?
  2. 如果是,如何正确添加它以便modCount正确,我没有得到ConcurrentModificationException

下面的完整方法,对ConcurrentModificationException发生的行进行评论:

public void construct() {
    tour = new ArrayList();
    ArrayList<City> lcl = new ArrayList(l.getCitys());

    tour.add(lcl.remove(0));
    tour.add(lcl.remove(1));

    while (!this.tourComplete()) {
        System.out.println(tour.size());
        Iterator tourit = tour.iterator();
        City g1 = (City) tourit.next();
        City g2 = (City) tour.get(lcl.indexOf(g1)+1);

        int gapDist = l.distanceBetweenCitys(g1, g2);

        while (tourit.hasNext()) {
            City C = null;
            int best = Integer.MAX_VALUE;

            for …
Run Code Online (Sandbox Code Playgroud)

java collections concurrency

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

Java泛型的未知问题

我试图在Java中第一次使用泛型类型,因为我只希望我的构造函数接受实现"Anealable"接口的类.由于我得到的唯一错误,我的代码出现问题是"类型的非法启动",试图使其工作并没有走得太远

这是我班级的代码

package simulated_anealing;

public class Crystal extends Thread {

    Object a;

    public  Crystal(<? implements Anealable> a)
    {
        this.a = a;
    }

}
Run Code Online (Sandbox Code Playgroud)

java generics interface

0
推荐指数
1
解决办法
179
查看次数