when does the main thread die?

The question was to generate random numbers between 1 and 99 using a thread. However the problem here is I don't know where does the "main thread is stopping" coming from? Doesn't the main thread die in the end? This is the sample output: Main thread stopping Random no = 57 Random no = 47 Random no = 96 Random no = 25 Random no = 74 Random no = 15 Random no = 46 Random no =

主线程何时死亡?

问题是使用线程生成1到99之间的随机数。 然而,这里的问题是我不知道“主线程停止”来自哪里? 主线不会死在最后? 这是示例输出: Main thread stopping Random no = 57 Random no = 47 Random no = 96 Random no = 25 Random no = 74 Random no = 15 Random no = 46 Random no = 90 Random no = 52 Random no = 97 Thread that generates random nos is stopping Mythread课程: public class MyThread extends Thread {

Spring Data Rest ManytoMany POST

First, let me explain my usecase. It's pretty straight forward. There is a User entity and a Service entity. I have ManytoMany association between User and Service using UserService as the Joined entity (joined table) Initially,there will be some set of users and some set of services. Users can subscribe to any Service at any point of time. In that case, an entry will be added to UserSer

Spring Data Rest ManytoMany POST

首先,让我解释一下我的用例。 这非常简单。 有一个用户实体和一个服务实体。 我在User和Service之间使用了ManytoMany关联,并使用UserService作为Join实体(连接表)。最初,会有一些用户和一些服务集。 用户可以在任何时间点订阅任何服务。 在这种情况下,一个条目将被添加到UserService。 但是,当我尝试创建一个新的UserService关联时,我收到空指针异常。 我可以单独创建用户和服务。 我的实体是:User.java packa

Confusion around Spring Security anonymous access using Java Config

I am using the following Java Config with Spring Security: protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .anyRequest().authenticated() .and() .httpBasic(); } Based on this configuration, all requests are authenticated. When you hit a controller without being authenticated, the AnonymousAuthenticationFilter w

使用Java Config混淆Spring Security匿名访问

我在Spring Security中使用以下Java Config: protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .anyRequest().authenticated() .and() .httpBasic(); } 基于此配置,所有请求都经过身份验证。 当您未经身份验证而击中控制器时, AnonymousAuthenticationFilter将使用username=anonymousUser, role=ROLE_ANONYMOUS为您创建一个Authen

Defensive copying of Number subclass

Please consider the following example: public final class ImmutableWrapper<T extends Number> { private final T value; public ImmutableWrapper(T value) { // a subclass of Number may be mutable // so, how to defensively copying the value? this.value = value; } public T getValue() { // the same here: how to return a copy? return value

Number子类的防御性复制

请考虑下面的例子: public final class ImmutableWrapper<T extends Number> { private final T value; public ImmutableWrapper(T value) { // a subclass of Number may be mutable // so, how to defensively copying the value? this.value = value; } public T getValue() { // the same here: how to return a copy? return value; } } 为了使这

When is the stateful session bean destroyed?

I am new to ejbs and I want to know whether a stateful session bean will be destroyed or not. I injected a stateful session bean in my servlet. Even after 30min I see that the bean is active. I am using jboss eap 6.0. I believe that HttpSession has nothing to do with a stateful session bean. I invalidated the HttpSession to make sure that HttpSession has nothing to do with the statful sessio

有状态会话Bean何时销毁?

我是ejbs的新手,我想知道有状态会话bean是否会被销毁。 我在我的servlet中注入了一个有状态的会话bean。 即使在30分钟后,我看到这个bean是活跃的。 我正在使用jboss eap 6.0。 我相信HttpSession与有状态会话bean无关。 我使HttpSession无效,以确保HttpSession与静态会话bean无关。 那么,如果我的应用程序有很多用户,并且如果我创建了一个新的bean,那么如果我的服务器的性能下降了,每个用户会如何呢? 容器如何管

Type List vs type ArrayList in Java

(1) List<?> myList = new ArrayList<?>(); (2) ArrayList<?> myList = new ArrayList<?>(); I understand that with (1), implementations of the List interface can be swapped. It seems that (1) is typically used in an application regardless of need (myself I always use this). I am wondering if anyone uses (2)? Also, how often (and can I please get an example) does the situa

在Java中键入列表与类型ArrayList

(1) List<?> myList = new ArrayList<?>(); (2) ArrayList<?> myList = new ArrayList<?>(); 我明白,在(1)中, List接口的实现可以交换。 看起来(1)通常用于应用程序而不管需要(我自己总是使用它)。 我想知道是否有人使用(2)? 此外,这种情况实际上需要多长时间(并且我可以请一个例子)使用(1)over(2)(即,where(2)不足以......除了编码界面和最佳实践等) 几乎总是第一个比

Hibernate hbm2ddl.auto possible values and what they do?

I really want to know more about the update, export and the values that could be given to hibernate.hbm2ddl.auto I need to know when to use the update and when not? And what is the alternative? These are changes that could happen over DB: New tables new columns in old tables columns deleted data type of a column changed a type of a column changed it attributes tables have been dr

Hibernate hbm2ddl.auto可能的值和他们做什么?

我真的想知道更多关于更新,导出和可以给hibernate.hbm2ddl.auto的值 我需要知道何时使用更新,何时不使用? 什么是替代方案? 这些是可能发生在数据库上的变化: 新表格 旧表中的新列 已删除列 列的数据类型已更改 一列的类型改变了它的属性 表已被删除 列的值已更改 在每种情况下,最好的解决方案是什么? 从社区文档: hibernate.hbm2ddl.auto在创建SessionFactory时自动验证或将模式DDL导出到数据

Java: Why is the Date constructor deprecated, and what do I use instead?

I come from the C# world, so not too experienced with Java yet. Was just told by Eclipse that the Date was deprecated. Person p = new Person(); p.setDateOfBirth(new Date(1985, 1, 1)); Why? And what (especially in cases like above) should be used instead? The specific Date constructor is deprecated, and a Calendar should be used instead. The JavaDoc for Date describes which constructors are

Java:为什么Date构造函数不推荐,我用什么来代替?

我来自C#世界,所以对Java还不太熟悉。 Eclipse刚刚告知, Date已被弃用。 Person p = new Person(); p.setDateOfBirth(new Date(1985, 1, 1)); 为什么? 而且应该使用什么(特别是在上面的情况下)呢? 具体的Date构造函数已被弃用,应该使用日历。 JavaDoc for Date描述哪些构造函数已被弃用,以及如何使用日历来替换它们。 java.util.Date类实际上并不被弃用,只是构造函数和其他一些构造函数/方法都被弃用了。 它

Should I use Java date and time classes or go with a 3rd party library like Joda Time?

I'm creating a web based system which will be used in countries from all over the world. One type of data which must be stored is dates and times. What are the pros and cons of using the Java date and time classes compared to 3rd party libraries such as Joda time? I guess these third party libraries exist for a good reason, but I've never really compared them myself. EDIT: Now that

我应该使用Java日期和时间类还是使用像Joda Time这样的第三方库?

我正在创建一个基于网络的系统,该系统将用于来自世界各地的国家。 必须存储的一种类型的数据是日期和时间。 与Joda时间等第三方库相比,使用Java日期和时间类有哪些优缺点? 我猜这些第三方库的存在是有原因的,但我从来没有真正比较过他们自己。 编辑:现在,Java 8已经发布,如果你可以使用它,那么! 在我看来, java.time比Joda Time更干净。 但是,如果您在Java-8之前卡住了,请继续阅读... Max询问使用Joda的优

What are the Xms and Xmx parameters when starting JVMs?

This question already has an answer here: How is the default Java heap size determined? 7 answers The flag Xmx specifies the maximum memory allocation pool for a Java virtual machine (JVM), while Xms specifies the initial memory allocation pool. This means that your JVM will be started with Xms amount of memory and will be able to use a maximum of Xmx amount of memory. For example, starti

启动JVM时,Xms和Xmx参数是什么?

这个问题在这里已经有了答案: 如何确定默认的Java堆大小? 7个答案 标志Xmx指定Java虚拟机(JVM)的最大内存分配池,而Xms指定初始内存分配池。 这意味着您的JVM将以Xms内存量启动,并且将能够使用最大Xmx内存量。 例如,像下面这样启动JVM将以256 MB的内存启动它,并允许进程使用高达2048 MB的内存: java -Xms256m -Xmx2048m 内存标志也可以用多种尺寸指定,例如千字节,兆字节等等。 -Xmx1024k -Xmx512m -Xmx8g