John,

If I had known you were going to do this, I would have given you different advice !

You are obviously running out of memory in the heap because of the number of integer 
ticket numbers stored and the overheads (hidden to you) of the objects in the tree set.

You can increase the size of the heap - it's a command line iooption - but it would be 
better to design another way out of the problem.

I suggest that you use an Entity Bean called NextNumberBean which has the 
responsibility for storing and issuing the next ticket number.

The key code would be a getNextNumber() method coded as follows :-


  |   int getNextNumber()  throws AllNumbersUsedException  {
  | 
  |     int nextNumber = getNextNumber();
  |     int startNumber = nextNumber;
  |     boolean numberUsed = true;
  |     while ( numberUsed )  {
  |       numberUsed = checkIfUsed( nextNumber );
  |       if ( numberUsed )  {
  |         nextNumber = getNextNumber();
  |         if ( nextNumber == startNumber )  {
  |           throw new AllNumbersUsedException();
  |           }
  |        }
  | 
  |     return nextNumber;
  |   }
  | 
  |   private int getNextNumber()  {
  | 
  |     lastIssuedNumber++;
  |     if ( lastIssuedNumber > MAXTICKETNUMBER )  {
  |       lastIssuedNumber = 1;
  |       }
  | 
  |     return storedLastNumber;
  | 
  |   }
  | 
  |   

The private method checkIfUsed, for which I have not supplied code, would do a 
findByPrimaryKey on the Tickets Entity Bean and return true if the Ticket with that 
primary key exists.

The integer lastIssuedNumber should normally be persisted using CMP.

The functionality should be clear.  The method increments   For each number, the 
method checks whether the ticket still exists on the database, and goes for the next 
(and then the next) until an unused number is found.  If all numbers are used - which 
you discover if you reach the start number without finding an unused slot - an 
exception is thrown.

Performance will not be as fast as on your version, but you will probably be able to 
issue a ticket in about 50 milliseconds, depending on the speed of your box.


James


View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3840474#3840474

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3840474


-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - 
digital self defense, top technical experts, no vendor pitches, 
unmatched networking opportunities. Visit www.blackhat.com
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to