java-7

Eligibility for escape analysis / stack allocation with Java 7

烈酒焚心 提交于 2019-11-28 12:07:06
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 time) { millis = time; } } public static void main(String[] args) { long r = 0; System.out.println("test1

ForkJoinPool seems to waste a thread

蹲街弑〆低调 提交于 2019-11-28 11:26:43
I'm comparing two variations on a test program. Both are operating with a 4-thread ForkJoinPool on a machine with four cores. In 'mode 1', I use the pool very much like an executor service. I toss a pile of tasks into ExecutorService.invokeAll . I get better performance than from an ordinary fixed thread executor service (even though there are calls to Lucene, that do some I/O, in there). There is no divide-and-conquer here. Literally, I do ExecutorService es = new ForkJoinPool(4); es.invokeAll(collection_of_Callables); In 'mode 2', I submit a single task to the pool, and in that task call

validateTree in Java 7.x doesnt work (in Java 6.x was fine)

百般思念 提交于 2019-11-28 11:19:16
My version of java is: Java Plug-in 10.3.1.255 Using JRE version 1.7.0_03-b05 Java HotSpot(TM) Client VM So when I had version 6.x everything was fine, after upgrading I've got this: Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: This function should be called while holding treeLock at java.awt.Component.checkTreeLock(Component.java:1196) at java.awt.Container.validateTree(Container.java:1682) at pl.recorder.ScenarioWindow.showUploadPanel(PlayerWindow.java:721) at pl.recorder.actions.UploadFilesAction.execute(DesignFilesAction.java:71) at pl.recorder.actions

How to compile mavenized OSGi 4.3 bundle with OpenJDK 7?

纵然是瞬间 提交于 2019-11-28 11:18:12
i am trying to compile my OSGi bundle against OSGi specification 4.3 using OpenJDK7 but i am getting error: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5:compile (default-compile) on project example: Compilation failure [ERROR] /tmp/baka/example/src/main/java/org/example/Activator.java:[14,24] error: type ServiceReference does not take parameters here is my Activator.java: package org.example; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; public class Activator implements

Double brace initialisation (anonymous inner class) with diamond operator

廉价感情. 提交于 2019-11-28 11:04:19
I am wondering why the second map declaration (using the diamond operator) does not compile when the first one does. Compilation error: error: cannot infer type arguments for HashMap; Map map2 = new HashMap<>() { reason: cannot use '<>' with anonymous inner classes where K,V are type-variables: K extends Object declared in class HashMap V extends Object declared in class HashMap Code: Map<String, String> map1 = new HashMap<String, String>() { //compiles fine { put("abc", "abc"); } }; Map<String, String> map2 = new HashMap<>() { //does not compile { put("abc", "abc"); } }; EDIT Thanks for your

How do I add a new Currency to java.util.Currency for an existing country code in Java 7?

五迷三道 提交于 2019-11-28 10:07:14
For example, the Chinese currency has the ISO 4217 code CNY . Since free global trading in that currency is restricted though, there's a second 'offshore' currency equivalent, called CNH . Wikipedia has a bit of summary of this all. In Java 7 , there's a method for updating the set of three letter ISO 4217 codes that the JVM ships with. However, it can't be used to add a separate currency code to an existing country code: it would replace CNY with CNH , which is no good for my purposes. How do I add CNH (which is not in the ISO 4217 list) to the set of available currencies in Java 7 , without

mark/reset exception during getAudioInputStream()

♀尐吖头ヾ 提交于 2019-11-28 09:57:52
问题 I posted a fix of a problem (explained below) but haven't been able to confirm if it solves the problem. Could someone with Java 7 try the out the following Applet and report back? It would be MUCH appreciated. AudioMixerDemo The problem that was reported to me was that the top row of buttons which require the load of a sound clip from a jarred resource are not working. The error points to the line where the audio file is being read and says a "mark/reset" I/O exception is being thrown. This

Get large directory content faster (java.io.File alternatives)

旧街凉风 提交于 2019-11-28 09:52:43
I've used the old, obsolete java.io.File.listFiles() for too long. The performance is not so good. It is: Expensive, since it creates a new File object for each entry. Slow, because you have to wait for the array to be completed before starting the processing. Very bad, especially if you need to work only on subset of the content. What are the alternatives? The Java 7's java.nio.file package can be used to enhance performance. Iterators The DirectoryStream<T> interface can be used to iterate over a directory without preloading its content into memory. While the old API creates an array of all

How Numeric literal with underscore works in java and why it was added as part of jdk 1.7 [duplicate]

最后都变了- 提交于 2019-11-28 09:34:59
This question already has an answer here: Java 7 underscore in numeric literals 8 answers Wierd Syntax - Underscores between digits [duplicate] 1 answer Can somebody please explain to me why this feature was added in JDK 7 and how it works? While going through the new features of JDK 7, I found following code. int i; //Java 7 allows underscore in integer i=3455_11_11; This is used to group the digits in your numeric (say for example for credit card etc) From Oracle Website : In Java SE 7 and later, any number of underscore characters (_) can appear anywhere between digits in a numerical

Java7 WatchService - Access Denied error trying to delete recursively watched nested directories (Windows only)

耗尽温柔 提交于 2019-11-28 09:08:43
I followed the Watching a Directory for Changes Java7 nio2 tutorial to recursively monitor the entire contents of a directory using the code sample WatchDir.java . While this works well on Linux and Mac, on Windows (tested on Vista and 7), trying to delete nested, watched folders using Windows Explorer fails with a message akin to "Access Denied: You need permission to perform this action" when a file exists in one of the nested directories. For example, if I watch a nested folder tree in Windows: -- Folder A -- Folder A1 -- File F and try to delete Folder A, I get the said Access Denied error