小编axt*_*avt的帖子

了解java.lang.Thread.State:WAITING(停车)

首先,一个非常愚蠢的问题,我只是想知道等待的"停车"意味着什么?线程是等待停放还是刚停放,因此处于等待状态?当停车发生时,需要多少CPU /内存资源?停放线程的目的是什么?

其次,通过在java线程API中查看park方法

除非许可证可用,否则禁用当前线程以进行线程调度.

如果许可证可用,那么它被消耗并且呼叫立即返回; 否则当前线程因线程调度而被禁用,并且在发生三件事之一之前处于休眠状态.....

英语不是我的主要语言,所以我很难理解,我打算"允许"作为"允许停放线程",所以接下来的问题:

  • 这是什么意思,什么是"许可",以及检查这些许可的人和方式是什么?
  • 这意味着什么:'如果有许可证就可以消费',它是否被"停放"了?
  • 如果第二点是真的,那么'停车'和'休眠'之间的区别是什么?如果我有许可证我可以永久停放,如果没有,我可以让它"休眠"吗?

谢谢

java multithreading

82
推荐指数
3
解决办法
7万
查看次数

春季3自动装配和junit测试

我的代码:

@Component
public class A {
    @Autowired
    private B b;

    public void method() {}
}

public interface X {...}

@Component
public class B implements X {
    ...
}
Run Code Online (Sandbox Code Playgroud)

我想在隔离类A中测试.我必须模拟B类吗?如果有,怎么样?因为它是自动装配的,并且没有可以发送模拟对象的setter.

junit spring autowired

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

hibernate jpa criteriabuilder忽略大小写查询

如何使用条件构建器来忽略大小写查询.对于描述属性,我想做类似的事情upper(description) like '%xyz%'

我有以下查询

CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();

    CriteriaQuery<Person> personCriteriaQuery = criteriaBuilder.createQuery(Person.class);
    Root<Person> personRoot = personCriteriaQuery.from(Person.class);

    personCriteriaQuery.select(personRoot);
    personCriteriaQuery.where(criteriaBuilder.like(personRoot.get(Person_.description), "%"+filter.getDescription().toUpperCase()+"%"));
    List<Person> pageResults = entityManager.createQuery(personCriteriaQuery).getResultList();
Run Code Online (Sandbox Code Playgroud)

jpa

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

WebApproot在Spring中

我收到此错误消息

[严重:异常将上下文初始化事件发送到类的监听器实例org.springframework.web.util.Log4jConfigListener java.lang.IllegalStateException:Web应用程序根系统属性已设置为不同的值:'webapp.root'= [C:\ Users\jaanlai\Documents\NetBeansProjects\absSovellus\build\web]而不是[C:\ Users\Administrator\Documents\NetBeansProjects\keycard2\build\web] - 在web.xml中为"webAppRootKey"context-param选择唯一值文件!

这很奇怪,因为我的文件中没有定义任何webAppRootKey.它是什么?

xml spring

38
推荐指数
3
解决办法
5万
查看次数

在Groovy中使用@Value Spring Annotation

我有一个groovy课程,我想在一个属性值自动装配.

例如:

public @Value("${valueA}" ) String valueA;
Run Code Online (Sandbox Code Playgroud)

在我的应用程序上下文中添加了property-placeholder

<context:property-placeholder location="classpath:spring/app.properties" />
Run Code Online (Sandbox Code Playgroud)

app.properties具有为"valueA"设置的值,因此理论上这应该在运行时填充我的类中的String valueA.

如果我使用java类,这个设置工作正常,但如果我使用groovy类则不行.

我收到编译错误:

错误:预期'$ valueA'是@ org.springframework.beans.factory.annotation.Value中java.lang.String类型的内联常量
错误:属性'value'的类型应为'java.lang.String'; 但在@ org.springframework.beans.factory.annotation.Value中找到了'java.lang.Object'类型

我只是想知道在使用groovy类时上述语法是否正确,如果不是,那么在运行时自动装配@Value参数的正确语法是什么.

groovy spring annotations properties

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

Spring MVC 3验证 - 无法找到默认提供程序

尝试设置Spring MVC验证时出错.

javax.validation.ValidationException: Unable to find a default provider
Run Code Online (Sandbox Code Playgroud)

我在文档中读到他们使用的默认提供程序是hibernate-validator.我是否需要包含此库才能使验证工作?即使我没有在我的项目中使用hibernate,也可以包含这个库吗?

java validation spring spring-mvc hibernate-validator

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

我在Java Puzzlers VI中发现了一个错误 - 有人可以解释一下吗?

看看Josh Bloch和William Pugh的这个java谜题视频,时间指数0:25:00-0:33:00.

其中一个发言者说,如果你使用小写boolean而不是Boolean,那么LIVING将被视为一个真正的"编译时常量",并且它在初始化时不再重要.

好吧,这一切都很好,但是,看看当你恢复静态初始化和构造函数之间的原始顺序时会发生什么,然后通过一个简单的"提取方法"操作来跟进它.这两个程序打印不同的输出:

public class Elvis {
    private static final Elvis ELVIS = new Elvis();

    private Elvis () {}
    private static final boolean LIVING = true;
    private final boolean alive = LIVING;
    private final boolean lives () {return alive;}

    public static void main(String[] args) {
        System.out.println(ELVIS.lives()); // prints true
    }
}
Run Code Online (Sandbox Code Playgroud)

并使用重构的returnTrue()方法

public class Elvis {
    private static final Elvis ELVIS = new Elvis();

    private Elvis () {} …
Run Code Online (Sandbox Code Playgroud)

java

23
推荐指数
2
解决办法
1015
查看次数

Spring MVC文件上传帮助

我一直在将spring集成到一个应用程序中,并且必须从表单重做文件上传.我知道Spring MVC提供了什么以及我需要做些什么来配置我的控制器才能上传文件.我已经阅读了足够的教程以便能够做到这一点,但是这些教程没有解释的是关于如何/一旦你拥有文件后如何实际处理文件的正确/最佳实践方法.下面是一些代码,类似于Spring MVC Docs上关于处理文件上传的代码,可以在
Spring MVC File Upload上找到

在下面的示例中,您可以看到它们向您显示了获取文件的所有操作,但它们只是说使用bean做一些事情

我已经检查了很多教程,他们似乎都让我到了这一点,但我真正想知道的是处理文件的最佳方法.此时我有一个文件,将此文件保存到服务器上的目录的最佳方法是什么?有人可以帮我这个吗?谢谢

public class FileUploadController extends SimpleFormController {

protected ModelAndView onSubmit(
    HttpServletRequest request,
    HttpServletResponse response,
    Object command,
    BindException errors) throws ServletException, IOException {

     // cast the bean
    FileUploadBean bean = (FileUploadBean) command;

     let's see if there's content there
    byte[] file = bean.getFile();
    if (file == null) {
         // hmm, that's strange, the user did not upload anything
    }

    //do something with the bean 
    return super.onSubmit(request, response, command, errors);
}
Run Code Online (Sandbox Code Playgroud)

java spring file-upload spring-mvc

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

JAXB无法处理接口

我认为这个问题已被问过一百万次,但没有一个解决方案对我有用.这是我的示例实现

public class FooImpl2 implements Foo {
    private int a = 100 ;
    private String b = "I am FooImpl2";
    private boolean c;

    public int getA() {
        return a;
    }
    public void setA(int a) {
        this.a = a;
    }
    public String getB() {
        return b;
    }
    public void setB(String b) {
        this.b = b;
    }
    public boolean isC() {
        return c;
    }
    public void setC(boolean c) {
        this.c = c;
    }

}

@XmlRootElement
@XmlSeeAlso({FooImpl1.class, FooImpl2.class})
public interface Foo {}

public …
Run Code Online (Sandbox Code Playgroud)

java jaxb

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

使用Spring MVC编码问题

我有一个创建用户的演示Web应用程序.当我尝试以其他语言(如法语)插入数据时,字符编码不正确.控制器上的代码是:

@SuppressWarnings("unchecked")
    @RequestMapping(value = "/user/create.htm", params={"id"}, method = RequestMethod.GET)
    public String edit(@RequestParam("id") Long id, ModelMap model) {
        System.out.println("id is " + id);
        User user = userService.get(id);

        model.put("user", user);
        return "user/create";
    }

    @RequestMapping(value = "/user/create.htm", method = RequestMethod.POST)
    public String save(@ModelAttribute("user") User user, BindingResult result) {

        System.out.println(user.getFirstName());
        System.out.println(user.getLastName());


        validator.validate(user, result);
        if(result.hasErrors()) {
            return "user/create"; 
        }

        userService.save(user);
        return "redirect:list.htm";
    }
Run Code Online (Sandbox Code Playgroud)

我的web.xml是:

...

    <filter>
        <filter-name>encoding-filter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>

    </filter>

    <filter-mapping>
        <filter-name>encoding-filter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

...
Run Code Online (Sandbox Code Playgroud)

而页面是:

<%@ page …
Run Code Online (Sandbox Code Playgroud)

spring spring-mvc

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