Welcome to the Java Programming Forums


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.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

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

  1. #1
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,659
    Thanks
    25
    Thanked 325 Times in 302 Posts

    Default 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.

    My current design is as follows:
    A GlobalRoute object contains the following class variables:
    Airport Origin - Reference to Memory which contains an Airport Object
    Airport Destination - Reference to Memory which contains an Airport Object
    int Distance - Ranges from 2 to 9363
    double PAX - Ranges from 0 to 3174.84
    int Fare - Ranges from 0 to 2995
    int Revenue - Ranges from 0 to 786598
    double ConnPAX - Ranges from -3174.84 to INF (theoretically INF, but in reality a really large number that I don't know what it is)
    double ConnRev - Ranges from 0.0 to INF
    double CurrentlyServedPAX - Ranges from 0.0 to ConnPAX
    Vector<Route> routeList - Vector of References to Route Objects, size ranges 0 to INF
    Vector<Company> companies - Vector of References to Company Objects, size ranges 1 to INF
    DecimalFormat df - Decimal Format Object for Stylistic Formatting
    DecimalFormat d2 - Decimal Format Object for Stylistic Formatting
    boolean beenFixed - boolean for checking


    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/


  2. #2
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    471
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

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

    Presumably you've tried increasing the Java heap size?

    Do you really need all those routes in memory at once, or could you read/write/replace them on demand from a database?

    What are the performance constraints? if speed is not a critical issue, a dynamic read/write/replace strategy to non-memory storage would seem the best way to go.

    It would help if you described the required operations on these objects - how will they be used?

  3. #3
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,659
    Thanks
    25
    Thanked 325 Times in 302 Posts

    Default 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/

  4. #4
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    471
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default 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.

  5. #5
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,301
    Thanks
    180
    Thanked 824 Times in 767 Posts
    Blog Entries
    5

    Default 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.

  6. #6
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    471
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

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

    Quote Originally Posted by copeg View Post
    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.

Similar Threads

  1. Reading from ResultSet to Object and from object Object Array
    By anmaston in forum What's Wrong With My Code?
    Replies: 4
    Last Post: April 7th, 2011, 06:11 AM
  2. Problem with designing threads & abstraction
    By gilme in forum What's Wrong With My Code?
    Replies: 6
    Last Post: June 14th, 2010, 06:48 AM
  3. 2D Object makes my object smaller, Why?
    By MassiveResponse in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 15th, 2010, 02:33 PM
  4. Problem in JSP Page Designing
    By vinothkumarrvk in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: March 10th, 2010, 12:09 AM
  5. Object o = new Object(); need help
    By zeeshanmirza in forum Object Oriented Programming
    Replies: 11
    Last Post: January 6th, 2010, 09:01 PM