java-7

Java G1 garbage collection in production

非 Y 不嫁゛ 提交于 2019-11-26 23:35:08
Since Java 7 is going to use the new G1 garbage collection by default is Java going to be able to handle an order of magnitude larger heap without supposed "devastating" GC pause times? Has anybody actually implemented G1 in production, what were your experiences? To be fair the only time I have seen really long GC pauses is on very large heaps, much more than a workstation would have. To clarify my question; will G1 open the gateway to heaps in the hundreds of GB? TB? It sounds like the point of G1 is to have smaller pause times, even to the point where it has the ability to specify a maximum

What is the difference between PermGen and Metaspace?

落爺英雄遲暮 提交于 2019-11-26 23:20:36
Until Java 7 there was an area in JVM memory called PermGen , where JVM used to keep its classes. In Java 8 it was removed and replaced by area called Metaspace . What are the most important differences between PermGen and Metaspace? The only difference I know is that java.lang.OutOfMemoryError: PermGen space can no longer be thrown and the VM parameter MaxPermSize is ignored. Mattias Jiderhamn The main difference from a user perspective - which I think the previous answer does not stress enough - is that Metaspace by default auto increases its size (up to what the underlying OS provides),

How to replace com.sun.image.codec.jpeg.JPEGImageEncoder in this code?

喜夏-厌秋 提交于 2019-11-26 22:45:00
问题 I have used com.sun.image.codec.jpeg.JPEGImageEncoder to handle JPEG images, like charts and others, in my webapp. Now, I am updating my machine to use JDK7, but this version deprecated this class. Below is the code that I need to change: public void processChart(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("image/jpeg"); out = response.getOutputStream(); response.setHeader("Pragma", "no-cache"); response.setHeader(

JDK 1.7 breaks backward compatibility? (generics)

萝らか妹 提交于 2019-11-26 22:03:17
问题 I've found similar topics, but overly complicated and not quite the same. So the thing is. Here's the(minimal) code which is fine on 1.6, but doesn't compile with 1.7 javac. public class Test { private static class A<T>{}; private static class B{}; private static class C{}; B doSomething(A<B> arg){ return new B(); } C doSomething(A<C> arg){ return new C(); } } On 1.7 the error is this: java: name clash: doSomething(Test.A<Test.C>) and doSomething(Test.A<Test.B>) have the same erasure I

JComboBox returning values

♀尐吖头ヾ 提交于 2019-11-26 21:41:18
问题 What method is used to return the selection chosen by the user? JPanel ageSelection = new JPanel(); JLabel age = new JLabel("Age:"); ArrayList<Integer> ageList = new ArrayList<Integer>(); for (int i = 1; i <= 100; ++i) { ageList.add(i); } DefaultComboBoxModel<Integer> modelAge = new DefaultComboBoxModel<Integer>(); for (Integer i : ageList) { modelAge.addElement(i); } JComboBox<Integer> ageEntries = new JComboBox<Integer>(); ageEntries.setModel(modelAge); ageEntries.addActionListener(new

Eligibility for escape analysis / stack allocation with Java 7

给你一囗甜甜゛ 提交于 2019-11-26 21:34:47
问题 I am doing some tests with escape analysis in Java 7 in order to better understand what objects are eligible to stack allocation. Here is the code I wrote to test stack allocation: import java.util.ArrayList; import java.util.Iterator; public class EscapeAnalysis { private static final long TIME_TO_TEST = 10L * 1000L; // 10s static class Timestamp { private long millis; public Timestamp(long millis) { this.millis = millis; } public long getTime() { return millis; } public void setTime(long

java.lang.VerifyError: Expecting a stackmap frame at branch target JDK 1.7

那年仲夏 提交于 2019-11-26 21:34:37
After upgrading to JDK 1.7 I am getting below exception: java.lang.VerifyError: Expecting a stackmap frame at branch target 71 in method com.abc.domain.myPackage.MyClass$JaxbAccessorM_getDescription_setDescription_java_lang_String.get(Ljava/lang/Object;)Ljava/lang/Object; at offset 20 at java.lang.Class.getDeclaredConstructors0(Native Method) at java.lang.Class.privateGetDeclaredConstructors(Class.java:2413) at java.lang.Class.getConstructor0(Class.java:2723) at java.lang.Class.newInstance0(Class.java:345) at java.lang.Class.newInstance(Class.java:327) at com.sun.xml.internal.bind.v2.runtime

Why diamond operator is used for Type Inference in Java 7?

安稳与你 提交于 2019-11-26 20:57:08
问题 List<String> list = new ArrayList(); will result in compiler warning. However the following example compiles without any warning: List<String> list = new ArrayList<>(); I'm curious why introducing of diamond operator is needed at all. Why not just have type inference on constructor if type argument is absent (as its already done for static methods in java and exploited by collection libraries like google guava) EDIT : Using millimoose answer as starting point I looked what type erasure

Maximum size of a method in Java 7 and 8

假装没事ソ 提交于 2019-11-26 20:11:00
I know that a method cannot be larger than 64 KB with Java. The limitation causes us problems with generated code from a JavaCC grammar. We had problems with Java 6 and were able to fix this by changing the grammar. Has the limit been changed for Java 7 or is it planned for Java 8? Just to make it clear. I don't need a method larger than 64 KB by myself. But I wrote a grammar which compiles to a very large method. According to JVMS7 : The fact that end_pc is exclusive is a historical mistake in the design of the Java virtual machine: if the Java virtual machine code for a method is exactly

Close resource quietly using try-with-resources

孤人 提交于 2019-11-26 19:59:54
问题 Is it possible to ignore the exception thrown when a resource is closed using a try-with-resources statement? Example: class MyResource implements AutoCloseable{ @Override public void close() throws Exception { throw new Exception("Could not close"); } public void read() throws Exception{ } } //this method prints an exception "Could not close" //I want to ignore it public static void test(){ try(MyResource r = new MyResource()){ r.read(); } catch (Exception e) { System.out.println("Exception: