Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

EOF Exception while inserting record through threading

 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

As you know Roberto Perillo made test class to test locking mechanism

https://coderanch.com/t/427863/Developer-Certification-SCJD/certification/Tests-Data-class-locking-mechanism


when I test my code while insert new record for e.g insert 10 new records the way implemented in above url ,I get EOF Exception in readContractor method at line that is bold in the below code snippet:


RECORD_SIZE=182
final byte[] input = new byte[RECORD_SIZE];
Contractor contractor = new Contractor();

synchronized (database) {
database.seek(locationInFile);
/*
* read the deleted flag value
*/
int deletedFlag =database.readUnsignedByte();
contractor.setDeletedFlag(Byte.parseByte(Integer.toString(deletedFlag)));
//contractor.setDeletedFlag(input[0]);
database.readFully(input);
}


Am I reading the deleted flag in correct way ?

In my assignment given that

"1 byte "deleted" flag. 0 implies valid record, 1 implies deleted record "


I am reading all the record of the database file in for loop in another method that call the readContractor

where RECORD__LENGTH =183
for (long locationInFile = FIRST_RECORD_POSITION; locationInFile < database.length(); locationInFile += RECORD_LENGTH) {
Contractor contractor = readContractor (locationInFile, recNo);

what I did wrong?


but when I tried to insert only one record with the CreateRecordThread that is given in above URL then it works fine .


It only brake my code when I do this


for (int i = 0; i < 10; i++) {
Thread creatingRecord = new CreatingRecordThread();
creatingRecord.start();


}

if i counter will run only one time then this will not brake my code but if counter will run more than one I am getting EOF Exception at line
int deletedFlag =database.readUnsignedByte();


something is wrong the way i read deleted flag?







 
Bartender
Posts: 3648
16
Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you get EOF Exception somewhere, that means you calculated the record number wrong some where. Check you record number generation. Then check your data file if there are extra square symbols in between each record.

I came across this and my problem was the record number generation.
 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exactly. All the tests do is call the methods from the public API of the interface provided by Sun concurrently. Please take a look and verify if you coded everything correctly.
 
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had to play around with what I sent in to that test class to get it to work properly. For instance, I included the valid flag in mine, so I had to send in something equivalent to 2 bytes. It's a great test but does need to be modified for individual users. Good luck
 
Roberto Perillo
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Anne Crace wrote:It's a great test but does need to be modified for individual users.



Exactly! Here's a piece of the post:

Some customization of this code will be necessary, according to the implementation of each developer.

 
Once upon a time there were three bears. And they were visted by a golden haired tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic