小编Adi*_*tya的帖子

Java中的多个垃圾收集器

我在我的机器上启动的每个Java进程默认情况下都有两个垃圾收集器.我正在通过JConsole检查这个.

示例 - 对于我当前运行的Eclipse.

PS MarkSweep

Collection Count - 221
Collection Time - 102118
Memory Pool Names - java.lang.String[4]
Run Code Online (Sandbox Code Playgroud)

PS清除

Collection Count - 241
Collection Time - 2428
Memory Pool Names - java.lang.String[2]
Run Code Online (Sandbox Code Playgroud)

我假设他们有重叠的池.当使用相同的池(伊甸园,幸存者,老一代)时,两个垃圾收集器如何协同工作?池之间的对象移动是否没有重叠(例如,当调用第二个算法时,从一个幸存者到另一个幸存者的移动)?即使不是,为什么每个池需要多个收集器呢?

在GC上看过这篇文章.它们指的是对不同的主要和次要GC使用不同的收集器,但似乎没有提到在同一个池上使用多个收集器.

java garbage-collection

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

在@Column中对nullable = true进行Hibernate处理

我正在使用Hibernate和一个由Mysql db支持的Springs.

这是与我用来创建条目的实体类似的实体

@Entity
@Table(name = "my_table") {

    @Basic
    @Column(name = "my_string", nullable = false)
    private String myString;
}
Run Code Online (Sandbox Code Playgroud)

sql定义是

CREATE TABLE `my_table` (
 `my_string` varchar(200) DEFAULT NULL,
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Run Code Online (Sandbox Code Playgroud)

虽然该表允许空值,但myString列根据JPA注释是不可为空的.这导致了不可预测的行为.

问:在插入时,是否在实体级强制执行不可为空的ALWAYS?或者是否存在可能被忽略的情况

我的期望是所有参赛作品都应该被拒绝.但是通过这种设置,许多条目(> 7000)进入了表格.有时我只能从spring获得DataIntegrityViolation异常

org.springframework.dao.DataIntegrityViolationException: not-null property references a null or transient value: ...; nested exception is org.hibernate.PropertyValueException: not-null property references a null or transient value: ....
    at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:652)
    at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:104)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:403)
    at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:58) 
    ....  
    ....
Caused by: org.hibernate.PropertyValueException: not-null property references a null or transient value: …
Run Code Online (Sandbox Code Playgroud)

java mysql orm hibernate jpa

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

反射IllegalArgumentException导致

更新 - 使问题更清楚.

在通过反射调用方法时获取ClassCastException的可能原因是什么?

在尝试通过反射调用方法时,我将以下stacktrace作为我的应用程序的一部分.

java.lang.IllegalArgumentException: java.lang.ClassCastException@21fea1fv
    at sun.reflect.GeneratedMethodAccessor332.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com..... 
    (remaining is my method stack trace)
Run Code Online (Sandbox Code Playgroud)

我尝试了一个示例类,并将不同类型的各种参数传递给它,但我总是得到一个这个例外.

java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
Run Code Online (Sandbox Code Playgroud)

更新 - 这是我为尝试重新创建异常而编写的示例代码

用于创建代理类的接口

package my.tests;

public interface ReflectionsInterface { 
    public abstract void doSomething();
}
Run Code Online (Sandbox Code Playgroud)

这是测试类

package my.tests;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class Reflections implements ReflectionsInterface {

    public static void main(String[] args) {
        Reflections reflections = new Reflections();
        ReflectionsInterface reflectionsProxy = …
Run Code Online (Sandbox Code Playgroud)

java reflection classcastexception illegalargumentexception

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