• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Double Whammy URLyBird 1.2.2

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hello fellow Developers,

For some reason I need to duplicate the code twice..

While updating a record I might try and run it 50000 times with only one thread choosing random record numbers from 0 to 100..

sometimes it will throw a null pointer error at 3000 or another random iterationn, sometimes it won't, sometimes it may finish the 50000 iteration.



This code basically calls a modified version of the FileAccess Class of the Andrew Monkhouse book.

The exception gets caught in this method.



For this two work I have to uncomment the code in the first method!!! I have tried synchronizing, locking, debugging. This is doing my head in, Way should I? have to run code twice for it to work...


Has anybody experienced this before...?

Regards Jas
 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey, Jason!

I see this is your first post here, so I'd like to give you a warm welcome to JavaRanch!!!

Also, I'd kindly like to ask you to take a look at the JavaRanch faq, which has lots of useful information about how to communicate your problems and get responses accordingly.

Could you please elaborate a little better your problem so we can effectively help you?

Thanks!
 
Jason Marshall
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Roberto,

Okay I'll give it another shot hopefully a bit more clearer..

I'm getting a Room object returned as NULL when it should not a be NULL. The only time it will be NULL is when there is not a room with that recNo. So for example in my database at the moment I have 200 Rooms with ID's from 0 - 199.

I am testing the update function of my server class. I run a while looop 50000 times and in that loop I randomly select a value from 1-100 (Which defenitly exist) as the recNo to update.

Now the problem is that intermitently and sometimes this will not happen a NULL is returned even though that recNo exists! For example it might happen at 23,456 or 996 and sometimes it may not happen at all.

At the moment I am just running ONE thread to isolate the problem..

To make this go away I have to uncomment the code in the first method, so basically I call getFromFile twice and it works!!! I don't know why and to me this is an unacceptable soultion.

I have tried Synchronizing but it still happens, has anybody had this before.?

Regards, Jason
 
Jason Marshall
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


If I un comment the bolded code then it works always!!!
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Jason, since you are "testing" and using a list collection ... how are you populating the list? Ideally if the data record is deleted or doesn't exist, you don't need to add it to the list. When you get the room object, are you doing it randomly like this:


If you do this, yes the room object may be null. So you do need to check if room is null before updating.

Also I noticed you are using long, if the Sun's provided interface use int for record number, there is no need to promote to long. If you are testing, shouldn't the list be shared? Why do you have it as local variable inside getRoomObject() method?

You may want to check out this thread for testing your Data class for URLyBird.
 
Jason Marshall
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your help K. Tsang,

I made the the ArrayList static and global and I don't know why this error was happening. I think that we are expected to know why our system behaves like it does and I cannot answer that one yet hmm.

Thanks for the link to data testing this will be very helpful..

Is the server classes the hardest part of this assignment or is there more curlers to come?

Cheers,

Jas
 
K. Tsang
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For most people the server classes and Data class locking are the hardest because not everyone exposes to manually locking and RMI before they do SCJD (assuming you don't do this kind of stuff at work).

So if you solve your current situation, you are 1/4 way throught.
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jason Marshall wrote:
Is the server classes the hardest part of this assignment or is there more curlers to come?



Hi Jason,

I will give a quick view how i experienced this assignment. Remark: I'm doing this assignment together with a full-time job and a social life, so I've only time to develop in the evenings and the weekends.

I started January 2009 with the SCJD-assignment and started with the Data-class (implementing sun's interface) and i made my own test providing 100% test coverage: a test-case for each possible situation (normal run of method, exceptions that could be thrown,...). Then i used Roberto Perillo's test-case to make sure my locking mechanism won't result in a deadlock. Each time when i made a change to Data I ran those tests again, to make sure changes don't have any effect on the program. Duration: 6 weeks.

I chose to use a seperate business layer, so i made my local implementation (+ full coverage test) and my RMI implementation (+ full coverage test + a test to see if my booking process is flawless). At the end of March i finished it (was 2 weeks unable to code due to illness).

And if everything goes as expected, this weekend i should complete my GUI and thus i should finish the coding part (and i did not spend more time each day on it then in the first 3 months).

So implementing sun's interface is the most important thing + making sure your code doesn't deadlock, so i spend most of my time doing that because if your code deadlocks you may receive 0/80 for locking and so it's almost impossible to pass. During development i used a wip-package and if my class was finished i javadoc'ed it completely and moved it to the appropriate package. So a finished class is really finished and i don't have to spend extra time to javadoc afterwards.
So you could easily say server class are the hardest and most important of the whole assignment. marking confirms this: 160 points on server, just 40 on gui, 70 on javadoc and 130 on general consideration + object oriented)

Kind regards and good luck,
Roel
 
Jason Marshall
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Roel,

Thanks very much for your time to explain to me how your assignment is going. I am the same as you and probably most of us here trying to develop whilst working full time jobs and trying to enjoy life as well.

Can I ask a few questions to you, I have run Roberto Perillo's test-case class and I find I do not ever get a deadlock, but if I increase the loop to about 1000+ I start getting JVM Thread out of memory exceptions, is this to be encountered? Also what does wip-package mean.

Once again thanks for your detailed explanation earlier.

Regards Jason
 
Roberto Perillo
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy, Jason!!!

I have run Roberto Perillo's test-case class and I find I do not ever get a deadlock



Way to go!!!
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jason Marshall wrote:Can I ask a few questions to you


Yes, you can.

Jason Marshall wrote:
I have run Roberto Perillo's test-case class and I find I do not ever get a deadlock, but if I increase the loop to about 1000+ I start getting JVM Thread out of memory exceptions, is this to be encountered?


I ran Roberto's test-case with a counter of 20000 and i never got an OutOfMemory-exception. So i'm afraid you have some kind of memory-leak. It certainly is weird to have such an exception. i guess you are the 1st person to report such a problem

Jason Marshall wrote:
Also what does wip-package mean.


wip = work in progress (as easy as that)
 
Roberto Perillo
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You know Jason, I also ran into OutOfMemoryExceptions, when I (just for curiosity) tested my Data class in standalone and networked mode at the same time (and for the networked mode, I created other test cases) and increased the loop's controller variable to about 100000000 (just for curiosity because this isn't really necessary). But we can consider 1000 a low number in this context. However, I don't know how they test our locking strategy (for instance, their controller variable can be 10 or 10000000!), so I don't really know if we got a problem here, but maybe you can consider reviewing your Data class/locking strategy to make sure you are not using more resources than needed, just for the sake of security.
 
Jason Marshall
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your comments guys,

I'll check now for memory leaks..

Cheers,
 
reply
    Bookmark Topic Watch Topic
  • New Topic