我正在运行的java进程在运行的第一个小时左右执行得很好.但是,性能会迅速降低.在进行性能分析时,我发现元空间垃圾收集经常发生,直到小时标记,然后失控:
我很确定我能够使用-XX:MaxMetaspaceSize选项来解决这个问题.但是,我想更多地了解为什么会出现这种行为.我无法想象为什么垃圾收集算法的行为会像这样.有没有人对更好的解决方案有解释或建议?谢谢
this在java中构造对象时,可以作为参数传递给方法吗?
考虑这样做会让我感到不安,但我不确定这是不是错了.采用以下假设示例:
public final class A {
private final B b;
private final List<String> words;
public A(B b) {
this.b = b;
words = new ArrayList<String>();
for(int i = 0; i < 10; i++) {
words.add(b.getNextStringFromUser(this));
}
}
public List<String> getWords() {
return words;
}
}
public class B {
// returns a String chosen by the user based on the current state of A
public String getNextStringFromUser(A a) {
List<String> wordsSoFar = a.getWords();
// ... omitted
}
} …Run Code Online (Sandbox Code Playgroud) 在阅读JVM规范时(就像我一样),当我遇到7个iconst_<i>操作码时,我感到非常惊讶.毕竟,只有一个字节可以播放.
我很少在代码中写入2,3,4或5的文字.我可以理解为什么-1,0和1可能会被特别对待,但我觉得设计师想要将4个珍贵的操作码吹到恰好相当小的数字上似乎很神奇.
有谁知道这是否有充分理由?我低估了这些的好处吗?
我想使用java.util.Set(和其他集合),但有一个扭曲:我想contains(),add()等等,总是调用对象equals()(这是基于身份而不是更平等的操作).我想我有办法,但它有很大的缺点.有没有正确的方法来做到这一点?对不起,如果我错过了一些明显的东西.
这就是我所做的:
public class OnlySelfEqual {
public final boolean equals(Object o){
return super.equals(o);
}
}
public class Example{
private Set<T extends OnlySelfEqual> set;
//etc
}
Run Code Online (Sandbox Code Playgroud)
我看到的主要问题(可能还有很多其他问题)是所有Ts必须从类扩展而不是实现接口,这是非常严格的.我想我想要的就像一个'反向'接口,它列出了子类型无法实现的方法(覆盖).我很确定不存在.有什么建议?
java ×4
jvm ×2
constructor ×1
final ×1
interface ×1
metaspace ×1
opcodes ×1
overriding ×1
this ×1