java

Interleaved parallel file read slower than sequential read?

I have implemented a small IO class, which can read from multiple and same files on different disks (e.g two hard disks containing the same file). In sequential case, both disks read 60MB/s in average over the file, but when I do an interleaved (e.g. 4k disk 1, 4k disk 2 then combine), the effective read speed is reduced to 40MB/s instea...

How do I deal with a ClassNotLoadedException while debugging?

So I'm (remotely) debugging some a java/jboss application in Eclipse, stepping through line by line. At one point, an array of GridSquare objects (GridSquare is a fairly simple, standalone class, contains a few properties and methods) is created by a method call, i.e: GridSquare[] squares = this.theGrid.getSquares(14, 18, 220, 222); ....

Prepend zero to byte

Hi, I'm reading file and I want to print byte value in 2 digits if it is less than 10 (example if byte=1 it should disply byte=01), I don't want to compare it like this: if(byte<10){ stringBuffer buf= new stringBuffer(); buf.append("0"+byte); } is there any built in method to do this, just like the format func...

Spring MVC and parsing HTML

I have a controller class as in the following code segment: @Controller public class SiteEntryController { @RequestMapping(value="/index.htm") public ModelAndView handleIndex( @RequestParam(value="enableStats", required=false) String enableStats) { ModelMap map = new ModelMap(); ........... return ne...

What does Semaphor.drainPermits do if no permits are available?

I'm trying to understand the contract of drainPermits in the Java Semaphore class The JavaDoc simply reads: public int drainPermits() Acquire and return all permits that are immediately available. Returns: the number of permits If no permits are currently available, does it block and wait until one is available? ...

Java howto paint on a graphic in an order I want

Hello In C# I saw already the SpriteBatch class (In the XNA plugin for XBOX games). In that class is it posible to paint in layers. Now I want to do the same in Java because I'm making braid (See my other questions) and I have an ArrayList from all the GameObjects and that list is not made in the correct paintoreder. For exemple: I ha...

What is a difference between <? super E> and <? extends E>?

I wonder if you could explain to me what is a difference between: <? super E> and <?extends E>. For instance when you take a look at class java.util.concurrent.LinkedBlockingQueue there is a following signature for constructor: public LinkedBlockingQueue(Collection<? extends E> c) and for one for the method: public int drainTo(Collectio...

Java equivalent of a Python functionality -> set(string)

I want to mimic a Python functionality in Java. In Python if I want unique characters in a string I can do just, text = "i am a string" print set(text) # o/p is set(['a', ' ', 'g', 'i', 'm', 'n', 's', 'r', 't']) How can I do this in Java trivially or directly? ...

Does java garbage scheduler depict it details in some form ?

The scheduler that runs as a daemon in JVM to garbage collect objects, can it be monitored with JMX.Do we have some way of telling that these are the objects it might garbage collect now.That way we can figure out that if we are creating specific objects of our classes and the instances are held up in memory of when they can be garbage c...

How to fix Java JNI DLL dependencies

Hi, I have a Java Application which has to load an DLL with a few dependencies. I copied all required DLLs in the same folder. The DLL I was set up uses the SeeingMachine FaceApi libraries. Now when I'm starting the Java application I will get an error the my DLL can't find the dependencies: Exception in thread "main" java.lang.Unsatis...

Netbeans 6.7 custom variable for ant task

Hi there! I've got a problem which I couldn't solve for a few days, please help me. I'd like to execute an ant-script within netbeans. the script needs a special classpath which a plugin/module made by myself puts into a "global-variable". The variable can be shown using the netbeans "Manage variables"-dialog. So it's working, I guess ...

How to best represent Constants (Enums) in the Database (INT vs VARCHAR)?

Hello, what is the best solution in terms of performance and "readability/good coding style" to represent a (Java) Enumeration (fixed set of constants) on the DB layer in regard to an integer (or any number datatype in general) vs a string representation. Caveat: There are some database systems that support "Enums" directly but this wo...

Call PL/SQL Web Toolkit procedures from Java

I need to call some PL/SQL procedures from my Java application. I can do it with JDBC. But the problem is that procedures are using the "PL/SQL Web Toolkit" and its packages (htp, owa _ util, owa _ cookie, ...). When I call them I get some exceptions as this: Exception in thread "main" java.sql.SQLException: ORA-06502: PL/SQL: numeric o...

Atomikos + Jetty in a Maven build environment - Classloader issue?

I am working on a project with multiple JDBC data sources and JTA. I use Maven as a build tool, and I'd like to use the Jetty plugin (6.1.20) to run the application during development. I am trying to configure Jetty to use Atomikos as the transaction manager. I'm following the Atomikos documentation from Jetty, but the Jetty startup fai...

Exclude individual JUnit Test methods without modifying the Test class?

Hi all, I'm currently re-using JUnit 4 tests from another project against my code. I obtain them directly from the other project's repository as part of my automated Ant build. This is great, as it ensures I keep my code green against the very latest version of the tests. However, there is a subset of tests that I never expect to pass ...

How to determine which classes are referenced in a compiled .Net or Java application?

I wonder if there's an easy way to determine which classes from a library are "used" by a compiled .NET or Java application, and I need to write a simple utility to do that (so using any of the available decompilers won't do the job). I don't need to analyze different inputs to figure out if a class is actually created for this or that ...

Sleep Windows from Java

Is there command to use on windows from java to make the computer sleep? ...

Setting font color on DefaultStyledDocument

I know that I can set the font size on a javax.swing.text.DefaultStyledDocument like this: public void apply(DefaultStyledDocument document) { final MutableAttributeSet attributeSet = new SimpleAttributeSet(); StyleConstants.setFontSize(attributeSet, 12); document.setCharacterAttributes(0, 80, attributeSet, false); } How d...

How to throw a checked exception from a java thread?

Hey, I'm writing a network application, in which I read packets of some custom binary format. And I'm starting a background thread to wait for incoming data. The problem is, that the compiler doesn't let me to put any code throwing (checked) exceptions into run(). It says: run() in (...).Listener cannot implement run() in java.lang.Runn...

Convert a list java.awt.geom.Point2D to a java.awt.geom.Area

I have a set of points that i want to turn into a closed polygon in Java. I'm currently trying to use java.awt.geom.Point2D and java.awt.geom.Area but can't figure out how to turn a group of the points into an Area. I think I can define a set of Line2Ds based on the points and then add those to the Areas, but that's a lot of work and I...