java

Why does Executors.newCachedThreadPool throw java.util.concurrent.RejectedExecutionException during submit

Number of tasks (threads) submitted is also not huge in this test scenario. ...

Random shuffling of an array in Android ?

I need to randomly shuffle the following Array in Android : int[] solutionArray = {1, 2, 3, 4, 5, 6, 6, 5, 4, 3, 2, 1}; Is there any function in the SDK to do that ? Txs. ...

Java <-> Scala interop: transparent List and Map conversion

I am learning Scala and I have a Java project to migrate to Scala. I want to migrate it by rewriting classes one-by-one and checking that new class didn't break the project. This Java project uses lots of java.util.List and java.util.Map. In new Scala classes I would like to use Scala’s List and Map to have good-looking Scala code. The...

How to use Java DB (named Derby) with hibernate

Hi guys i can connect Derby via Eclipse Database Development but i cannot connect Derby with same url with Eclipse Database Development's through Hibernate. Error :"Caused by: java.sql.SQLException: Another instance of Derby may have already booted the database " ...

Install Jboss application server on win vista

Hi all, I want to install Jboss app server 4.2.2. I've downloaded .zip installation from their website and here is what I get when I extract the zip file like in the picture below : I've used their tutorial guide to try to install it but I can't get it working .. http://www.jboss.org/file-access/default/members/jbossas/freezone/docs/I...

Changing class variables by means of a second and third class

I'm working on a personal project and at the same time experimenting with it. I've got 3 classes contained in 3 files: Calculate.java, Geometry.java, and Test.java. Geometry.java so far only contains some variables I want to work with, the get/set methods along with a constructor method. package project; public class Geometry { ...

Anonymous class binary names

I have the following problem: 1) There is some abstract class A with several anonymous subclasses stored in the static fields of A. There is circular dependency between two of the anonymous subclasses. The code of that abstract class is similar to following: class A implements Serializable { public static final A _1 = new A() { ...

Spring / JTA / JPA unit test : Rollback not working.

I am trying to test an entity EJB3 with Spring. The EJB itself does not uses Spring and I would like to keep duplications of the production JPA configuration minimal (ie not duplicating persistence.xml for exemple). My unit tests seems to work but even though my unit tests should be transactionnal, data is persisted between the various...

Help! I get OutofMemory while Retrieving web pages.

I am retrieving the HTML from the web. I get "java.lang.OutOfMemoryError: Java heap space (repl-1:3)" ;; fetch: URL -> String ;; fetch returns the string of the HTML url (defn fetch [url] (with-open [stream (. url openStream)] (let [buffer (BufferedReader. (InputStreamReader. stream))] (apply str (line-seq buffer))))) ...

Import Spring config file based on property in .properties file

In my Spring xml configuration I'm trying to get something like this to work: <beans> <import resource="${file.to.import}" /> <!-- Other bean definitions --> </beans> I want to decide which file to import based on a property in a properties file. I know that I can use a System property, but I can't add a property to the JVM a...

Assigning a value when an exception occurs (Java)

Hello, Here is some sample code to illustrate our issue: A a = null; try { a = new A(); a = doSomethingThatWillThrowAnException(); } finally { System.out.println("A = " + a); } The question is what is the value of 'a' as printed in the finally block... I am not sure and I think I stumbled across something that might not be com...

Prepared statement - using a function as part of the where clause

I am working with a Java prepared statement that gets data from an Oracle database. Due to some performance problems, the query uses a "virtual column" as an index. The query looks like this: String status = "processed"; String customerId = 123; String query = "SELECT DISTINCT trans_id FROM trans WHERE status = " + status + " AND FN_GE...

how to database connectivity between mysql and eclipse java

how to database connectivity between mysql and eclipse java? plz tell me hw it can be done? ...

Swing custon JComponent size

I want to create a custom JComponent (specifically a custom JToggleButton) that has a custom appearance. What i want to do is simply override the default painting of the component and draw something of my own (an image for instance) This is NOT a question on how to do that (I am fairly proficient with Java2D). What i want to ask is what...

using quartz in a web app with spring

Hello good fellas! I've created a small console application to see how quartz work and it was easy to create an applicationcontext object inside the main method to get the cron run. OK now I'm in a real project managed by maven and which is using cron jobs defined in some of the modules. Each of the module has his own spring config file...

Overriding fillInStackTrace for a standard JVM Exceptions

Hi, If I'm using reflection and I want to find if a method is implemented or not, i can use the getMethod() method. This method throws a NoSuchMethodException. Is there a way to overload the fillInStackTrace of this Exception to optimize the performance ? Right now, about 40% of the time is spent in this Method. I'm using a framewor...

java compare objects: using reflection??

I have an object which itself has multiple objects as fields. The question I have is, I have two objects of these kind and I want to compare these two. I know I can do equals, comparator etc. but is there a way to use reflection to get the properties of the object and make comparison. for example, if I have a Car object, which as wheel...

Transaction state in JDBC

Is there a way to know if a transaction is in an "ongoing" state in JDBC? I found nothing in the Connection API. Thanks ...

Avoiding multiple repopulations of the same cache region (due to concurrency)

Hello I have a high traffic website and I use hibernate. I also use ehcache to cache some entities and queries which are required to generate the pages. The problem is "parallel cache misses" and the long explanation is that when the application boots and the cache regions are cold each cache region is being populated many times (inste...

Java: Converting a double to a String

Hi! I have a double whose value is 10,000,000.00 (ten millions). I have to convert it to a String. When using the method "toString" I am getting the String "1.0E7" which is correct following the specification. Unfortunately I need the String "10,000,000.00" (or the equivalent depending on the locale). How can achieve this? Thanks in a...