The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

What is the best way of designing this object?

Ok, so I'm writing an airline simulator thingy. I have a database for the program to use in order to collect its data to run the simulation.

I have an object called GlobalRoute and an object called Route. A GlobalRoute contains the historical data from the database and some data about how things have changed for the current running simulation.
I also have an object called Airport, that contains the IATA code, State, Coordinates, Country, ect.

The problem I am having is I am running into memory walls when I attempt to import the data from the database. The memory wall is consistently being hit at the same time, which is while it is reading in the GlobalRoutes. There are 95324 GlobalRoutes that it needs to read into the program. That seems to be a tad much for the computer to handle, so I am trying to make my GlobalRoute objects as memory efficient as possible, as far as variables go, to hopefully allow me to read in more objects.

I have currently capped off the number of GlobalRoutes that it reads in to 4182 to prevent any possible memory problem while reading in and to still provide plenty of memory to run with. I would like to be able to read them all in though, since what I currently have is only 4% of what I need.

Are there any suggestions for what I can do to make things more memory efficient?

NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

When asking for help, please follow these guidelines to receive better and more prompt help:
1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
2. Give full details of errors and provide us with as much information about the situation as possible.
3. Give us an example of what the output should look like when done correctly.

Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

Re: What is the best way of designing this object?

I don't want to increase the Java heap size, because that would require me to do so on all machines that will run the program.

Well the purpose is where it gets interesting. Being a simulation, I have a very complex AI object where the computer effectively tries to operate and manage its own airline. In order for it to determine where it should begin operations, it needs to be able to compare all the routes based on 7 or so different parameters. Additionally, a human can join in to also compete, or multiple humans on a network. This creates an issue because our database is only a MS Access database since that is all I can get my hands on at the moment, which means we cannot have multiple people accessing the database at once, which causes a problem if multiple people are attempting to read data. This is not a problem when all the data is read in on the start of program, since multiple users are only accessing the data at the start of the program.

NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

When asking for help, please follow these guidelines to receive better and more prompt help:
1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
2. Give full details of errors and provide us with as much information about the situation as possible.
3. Give us an example of what the output should look like when done correctly.

Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

Re: What is the best way of designing this object?

It sounds like the problem is logistical and database related - there are plenty of no-cost and open-source Java database engines out there (e.g. Apache Derby, JODB, etc.), why not use one of those instead? You might find an object database like JOBD ideally suited.

Re: What is the best way of designing this object?

Does the model change often? If not, you could go the route of the comparison calculations once and store that in memory - from that respect you might be able to reduce the memory usage.

Second dlorde's advice on changing away from MSAccess, which is not well designed from a centralized model to be shared by multiple clients (in addition to Derby, there is Mysql, Postgres, and Oracle (not free outside a developement environment). From this perspective the comparison only needs to rely on the values it uses and an identifier which can be used to then pull more info from the backend.

I don't want to increase the Java heap size, because that would require me to do so on all machines that will run the program.

If you deploy the app using something like webstart, you just need to change the initial configuration in the jnlp file. You could also deploy the jar wrapped in platform specific modules (like an exe for windows, or package for mac) and specify the JVM options that way.

Re: What is the best way of designing this object?

Originally Posted by copeg

If you deploy the app using something like webstart, you just need to change the initial configuration in the jnlp file. You could also deploy the jar wrapped in platform specific modules (like an exe for windows, or package for mac) and specify the JVM options that way.

Good point. Also, it might be worth considering delegating the heavy-duty work to a server-side process, either via the database (procedures, etc.), or servlet, etc.