Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!

Colin Duggan

Ranch Hand
+ Follow
since Feb 23, 2008
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Colin Duggan

I completed OCMJD back in July and my life just hasnt been the same not havin a certification to focus on

What follow on exams are people doing?
Hi,

I'm using Jersey Client along with HttpClient4 to connect to a JAX-WS web service. The service URL is protected by SSL.

I'm configuring my HttpClient to include a Scheme for SSL using port 443. The JerseyClient attempts to connect to the service however it does so using regular HTTP on port 80. If i run the code in debug and modify the port to use 443 i can see the request being sent (i have debug enabled in my logger) however the connection then gets reset and the request fails.



I need to use the HttpClient along with JerseyClient so i can have control over the credentials which are set. Does anyone have any ideas?

9 years ago
Hi guys,got my result this morning and delighted to say I passed. No score was included in the email, looks like you have to fail to get that!

Thanks to all that help out on the forum especially Roel and Roberto!
9 years ago
Just re read the submission instructions and see that the submission jar contains the executable jar as does the one your script creates. Thanks
Hi Roel, thanks for the test and build script. I'm trying to send off my submission and running your build script creates the jars however when i try and run the submission jar i get this;

failed to load main-class manifest attribute from



when i look in my manifest file no main class has been specified. In the build script i see that only the name value is set in the manifest.



How does the submission jar write the main class to the manifest if its not mentioned here?Thanks

when the application shuts down should i be waiting for any existing threads , which hold record locks, to finish before i persist my record cache to the db file and close the RAF instance? I could force the shutdown method to wait on the same lock as the threads in the lock method until my lock map is empty and then shutdown?
it was a choice between synchronizing on my singleton class or using the lock API. I choose the lock API which ment I could no longer synchronize the lock or unlock methods. I use only the basic features of the API so not a lot of benefit. In the future the way threads release locks could be enhanced by using separate lock conditions for each thread but i haven't implemented this and only mentioned as a possible future enhancement. Looking at it now, the way i have it implemented does not offer anything additional so i will consider reverting to just keeping all methods synchronzed and then just synchronize on the Data instance in my lock and unlock methods.
I've read a lot of topics about the locking mechanism and just want to get your opinion on whether my strategy holds up?

1.Lock and unlock method are not synchronized - all other methods in the class are synchronized
2.Uses reentrant lock to create critical section for threads looking for record lock
3.Once thread has reentrant lock it calls a synchronized method to check if record exists
4.Waits on a reentrant lock Condition object inside while loop if record lock held by another thread
5.When record lock is available thread calls synchronized doesRecordExist method again to verify record was not deleted
6.Creates cookie and adds to map
7.Releases reentrant lock and exits lock method

With this approach it is possible that thread A can execute one of my public synchronized methods while Thread B is inside the lock or unlock method. However because the method to check if a record exists is synchronized it means that the lock method will have to wait for any CRUD operations to complete before it can check if record exists. So no data corruption in my opinion.

To lock the database I then have a synchronized method which closes the RandomAccessFile object in my DataFileAccess class (this class does all IO operations on data file) and then set its reference to null. Because the method is synchronized it means that no other CRUD operation can occur at this point. It is possible that another running thread could enter the lock method after this and attempt to obtain a lock for a record however an IllegalStateException will be thrown when the check is called from the lock method to see if a record exists or not. It is possible also that another thread who was waiting to enter a synchronized block to update or delete a record does so but an IllegalStateException will be thrown because the DataFileAccess reference is no longer valid.

Does this sound like a valid approach?
when you say

The shut down hook will just invoke that method through some intermediate method of GuiController



How is this possible? If the shutdown hook in Data.java is triggered when the JVM is shutting down how can a method in GUIController call the shutdown hook?
Is it not enough to have the shutdown hook in the Data class constructor which calls saveRecords? This would always be called when the application is shutdown. I'm just trying to understand why we might need an explicit call in the GUIController.thanks
ya thats it, my deletes of non-existing records is pretty high;

in a run of 2500 iterations

total deleted records (reused and new) = 2249
total records created or reused =2500
total failed deletions = 251

and i end up with 282 records

with always deleting record 1: total number of records at the end was 31 (the 1st record is always reused for the new records)


the total number of records could only be 31 if we could ensure that order in which the delete and create threads execute. so if create executes when no records have been deleted then a new one will end up being created and this could happen alot over the course of 2500 iterations resulting in a large record file
yep that was the problem, thanks guys.

Why i used the list in the first place. I thought it would be a good idea to keep the deleted records in a separate list so i wouldn't have to set its String[] to null. I wanted to be able write the record back to the file on shutdown (with is valid flag set to 1). However a simple change to just write the valid flag bit when a record has been deleted solves this.

Roel, i tried the tests you mentioned earlier, running with 2500 iterations and things are looking alot better, only difference being in the second test

with deleting a record with index between 0 and 50: total number of records at the end was 49 (sometimes a delete fails because the record does not exist, so new records are just added)

In my case the number of records at the end is higher. cheers
Cheers Roel makes perfect sense. The third point for me is odd because my code to reuse an existing record is only a few lines long, i just get the first element ,deletedRecords.get(0) , in my list of deleted records list , add to my record cache along with the string[] and finally remove the deleted recordNo from my list ,deletedRecords.remove(0), so not much room to mess up


sorry to reopen this. Submitting in couple of weeks and need to close this. I did some more testing and noticed that my problems occur when writing to my memory cache in the create method. If i leave out the create thread in the test program i can run 1000000+ threads without issue but when i add back in the create thread i can only run approx 20000 iterations before getting an OOM. This number decreases even more when i add my logic in create method to reuse deleted records. Did you guys do anything different to make your maps more efficient? Any suggestions would be great! Thanks