java

Running java programs in one runtime instance

Hi, I am wondering if such thing is possible: I have a java program that takes arguments and gives output to the console. What i need is to run it multiple times - it (jar file) runs smoothly but the overhead for starting and stoping java runtime is way to big. Is there a way to instantiate java runtime (or vm, I'm not sure how to call...

Using maven to build/deploy/use projects with JNI.

I am trying to use maven to build a project that depends on a JNI wrapper around the OpenCV computer vision library. I've been able to "maven-ize" the OpenCV wrapper here: http://ubaa.net/shared/processing/opencv/ by using FreeHEP's NAR maven plugin, but the documentation for that plugin is somewhat lacking. I've been able to create ...

How can I optimally update a single property in an object using Hibernate?

I have an object: public class Data { private long id; private long referenceCount; private Blob dataCache; /* getters and setters for the above */ } Corresponding to this is a mapping: <hibernate-mapping> <class name=Data" table=DATA"> <id name=id" type="long"> <column name...

org.hibernate.hql.ast.QuerySyntaxException with Hibernate

Hello, I'm new to using Hibernate with Java. I'm getting the following exception. The stuff that I found online regarding this error didn't seem to help. Any ideas? The Exception: java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: ApplPerfStats is not mapped [select count(c) from ApplPerfStats c] at or...

Order of method invocation

Hi everybody I write java class with the main method and I invoke method from matlab which takes long time and the program run other method which takes less time before the method of matlab. I want to run the method from matlab to be execute first then I want the other method to execute so can you help me please Thanks ...

JMS vs Webservices

What are the big advantages from JMS over Webservices or vice versa? (Are webservices bloated? Is JMS overall better for providing interfaces?) ...

TCP socket timeout configuration

I have a Java application which uses a third-party COM component through a Java-COM bridge. This COM component opens a socket connection to a remote host. This host can take some time to respond, and I suspicious that I'm getting a timeout. I'm not sure because as I said, it's a closed-source third-party component. The API of this comp...

What is the best way to format a string in Scala?

I was wondering what the best way to format a string would be in Scala. I'm reimplementing the toString method for a class, and it's a rather long and complex string. I thought about using String.format but it seems to have problems with Scala. Is there a native Scala function for doing this? ...

Factory method pattern in java using generics, how to?

I have code that looks like follows: public interface BaseDAO{ // marker interface } public interface CustomerDAO extends BaseDAO{ public void createCustomer(); public void deleteCustomer(); public Customer getCustomer(int id); // etc } public abstract class DAOFactory { public BaseDAO getCustomerDAO(); public static DAOFactory getIn...

Strange Exception on getGeneratedKeys() with JDBC for MySQL 5.1

Hello, I'm using JDBC to insert a row into a MYSQL database. I build a parameterized command, execute it and attempt to retrieve the auto generated keys as follows: String sql = "INSERT IGNORE INTO `users` (`email`, `pass-hash`) VALUES (?, ?)"; Connection conn = SQLAccess.getConnection(); PreparedStatement ps = conn.prepareStatement(...

Automatically generating source and doc jars in Netbeans

Is there a way to automatically generate source and javadoc jars in Netbeans? Ideally I would like to place jars of my source and JavaDoc in the dist folder each time i build. ...

Why does Java Pattern class use a factory method rather than constructor?

There's a good discussion of this in the general case. However, I was wondering specifically why the Pattern class uses the compile static method to create an object, rather than the constructor? Seems to me to be more intuitive to use a constructor. ...

JDBC connection to Oracle Clustered

Hello, I would like to connect to a clustered Oracle database described by this TNS: MYDB= (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = host1)(PORT = 41521)) (ADDRESS = (PROTOCOL = TCP)(HOST = host2)(PORT = 41521)) (LOAD_BALANCE = yes) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME= PDSALPO) ...

Java hashmaps without the value?

Let's say I want to put words in a data structure and I want to have constant time lookups to see if the word is in this data structure. All I want to do is to see if the word exists. Would I use a HashMap (containsKey()) for this? HashMaps use key->value pairings, but in my case I don't have a value. Of course I could use null for t...

Is this correct way of using javax.annotation from JSR305 ?

I've recently added the RI for JSR305 into my project and have been adding annotations to my interfaces like this: public interface AccountService { @Nullable AccountResult consolidate( @Nonnull Date from, @Nonnull Date to ) } In the spirit of the JSR (as described here), do you think I'm misusing the annotations by using them in ...

Servlet parameters and doPut

Trying to get parameters from a PUT request using HttpServlet#doPut: public void doPut(HttpServletRequest request, HttpServletResponse response) { String name = request.getParameter("name"); // name is null } Using curl to send the request: curl -X PUT \ --data "name=batman" \ --header "Content-Type: text/plain" ...

Load balance web application

There are load balanced tomcat web servers. Every request could be served by different tomcat server. How could we take care of this while writing code for the j2ee (struts) based web application? ...

Breaking out of a recursion in java

The recursion is sort of a 'divide and conquer' style, it splits up while getting smaller (Tree data structure), and I want it to break completely if a violation is found, meaning break all the recursive paths, and return true. Is this possible? ...

Spring MVC isFormSubmission() equivalent for annotations?

With Spring MVC, it's easy to express a concept like "A user is submitting the form if they use POST or if they include the 'isSubmit' parameter." You'd just extend SimpleFormController and override the isFormSubmission method. However, Spring MVC now uses these neat annotations like @RequestMapping to handle requests. @RequestMapping...

Simple way to rename all java classes, fields and methods?

I need to send part of our code for one of our tool vendors, and I want to remove all references to our project from our classes. There are dozens of obfuscators available for java, but I don't want to scramble the code, just do as simple and consistent as possible renaming. (Maybe this is configurable in some of the obfuscators?) Best ...