[SOLVED] Jme3 Beginner: What’s Faster?

Getting now:

[java]Exception in thread “main” java.lang.OutOfMemoryError: Java heap space

at java.util.Arrays.copyOf(Unknown Source)

at java.lang.AbstractStringBuilder.expandCapacity(Unknown Source)

at java.lang.AbstractStringBuilder.append(Unknown Source)

at java.lang.StringBuilder.append(Unknown Source)

at java.lang.StringBuilder.append(Unknown Source)

at java.util.AbstractCollection.toString(Unknown Source)

at java.lang.String.valueOf(Unknown Source)

at java.lang.StringBuilder.append(Unknown Source)[/java]

when I try to system.out.println the content to test if it’s accurate.

Well, since you are trying to turn the whole collection into one giant string… that’s not really surprising with default heap settings.

I realy think the delay is from after the line is parses and using a hashmap is calls the specific event on the fly (whether rotate, move, etc) using that code:

[java]/** Constructor that initializes the event read /

public Jme3CreateEvent(ArrayList<String> allEventsList) {

event = allEventsList;



public void register(Spatial spa) {

mySpatial = spa;



public void run() {

* iterate thru the parameters and pass them back to main animation function */

ListIterator<String> it = event.listIterator();

if (event.size() != 7)


throw new IllegalArgumentException("Error: Event size incorrect - Check the event passed.");




trigger_time = Float.parseFloat(it.next().trim());

event_type = it.next();

type = it.next();

id = it.next();

x = Float.parseFloat(it.next().trim());

y = Float.parseFloat(it.next().trim());

z = Float.parseFloat(it.next().trim());


// call the animator jme to execute a create drive command

myApp.createSpatials(trigger_time, type, id, x, y, z);



I tried the same thing w/o attaching the hashmap and its less than 1 second. It’s this function in command design pattern that’s slowing me down:

[java]private void attachCommands(HashMap<String, Command> hm2) {

hm2.put(“create”, new Jme3CreateEvent(AllEventsList));

hm2.put(“rotate”,new Jme3RotateEvent(AllEventsList));

hm2.put(“move”,new Jme3MoveEvent(AllEventsList));

hm2.put(“accelerate”,new Jme3AccelerateEvent(AllEventsList));

hm2.put(“decelerate”,new Jme3DecelerateEvent(AllEventsList));

// add all other events here


so when the class in the post above is called this is when the process slows down. Any recommendations on speeding things up?

How many times is that method called? And if the answer isn’t “once”… then why is it getting AllEventsLis every time.

…and if the answer is “just once”… then there is nothing in there that would take a long time unless the constructors of the event classes are doing something strange.

It sounds ok. I don’t know the details, though… or what the hashmap is doing for you in this case, etc.

It’s not the normal way I’d think to execute a series of timed events but I don’t know the details or motivations.

just checked , it’s only being called once.

the classes called are something exactly similar to the create class I posted above. I don’t see anything strange :s

and there’s this function inside the main adapter/reader class that connects to the hashmap values


// register all commands with mySpatial

for(Command cmd : hm.values()) {cmd.register(mySpatial);}

Command theCmd = hm.get(part1);

// execute the command

if(theCmd != null)





Ok. So it’s not that method that’s slow. It’s something using the results of that method that is slow. That method should complete in nanoseconds.

Note: my last post was about the attach method.

It might be time for you to learn how to profile code. It’s too hard for us when we don’t run the code and can only see little windows of it at a time.

I see.

well I use the command design pattern (the hashmap u see) to call other classes like the one I posted above (Jme3CreateEvent.java). Is there anything funky i’m doing there? the Jme3CreateEvent.java itself will call a createSpatial function inside the main animation class. And so on for the rest of the events (rotateEvent.java will call rotateSpatial() etc)

It’s not a bad design is it?

The idea was instead of having a bunch of ugly if statements in my main file that do something like this:


if (event == create) then createSpatial(…);

if (event == rotate) then rotateSpatial(…);



I implemented a command design pattern that takes that event and relates it to a class Create, Rotate, Move, etc as a better coding practice.

So every class initializes the variables and passes them to the related function in the main animation file to animate it.

Sure… but then why do you need them in a hashmap? (Note: the hashmap is not the cause of your performance problems… I just don’t understand what’s going on is all.)

I use a hashmap just as a clean way to read the event (say create) and call create.java nothing more.

What I am doing is using Cinematics to read cinematic events from a trace file to create animation for my simulation.

So I have a trace file that I parse it (and convert it to Cinematic events - around 200,000 events that is ) and then animates them accordingly

I think the best way to do it is like @normen suggested, by using multi-threading. Any existing example on how to do that with Jme?

Man, I posted the link with a detailed example I wrote up in that same post :roll:


1 Like

PS: It may be too late, but, if you are using the jmonkeyplatform, you can go to Tool>Plugins and find a Java Profiler there that will tell you how many objects are created anb which methods are called how often and how long etc…