• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Thread Safety & RandonAccessfile

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

First of all an Into: Since I am using RMI I have no control over the threads. I have determined that my data class is thread safe(No midification of the class variables inside the methods) and client identification not a problem because of use of cookies. So I am using only a single data class.

But inside the data class I am confused whether to use a single RandomAcces file or one instance of it per method. When I look into RA class, there are only two class variables.

private FileDescriptor fd;
private FileChannel channel = null;
But this will go an for ever as I have to determine if FileDescriptor is thread safe...

Is this too much for the assignment. Can I just put an end to this and create RA instances for each method?.

Thanks for your time.
 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure I understand your problem correctly. If you use only one RA file (like I do), you'll definitely have to make sure that no two methods are called synchronously, as inside a method, you'll probably set the file pointer to a position and the read or write there. This is something you can't allow two threads to do at the same time. So, synchronizing your Data methods would be necessary, no matter whether RAFile is thread safe or not.
 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alternatively, if you choose to create a new RandomAccessFile object per method, you need to be aware that the number of FileDescriptors available within the system is Operating System dependant - or at the very least not unlimited. That means two things:

1) You may run out of FileDescriptors (which may or may not be acceptable to you).

2) This will probably happen with different numbers of users depending on the underlying OS.

However, if neither thing happens before having an unrealistic number of users, you may be happy to accept the limitation and just document your choices.
 
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Thirumurugan

1.Why you use FileChannel I don't think that nio is allowed.
2.You can use only one (synchronized) RAF for all your clients.
3.You can also use more than one RAFs but you need to find a way to synchronize
them, thats why the solution from 2 is easy/better.

Regads M.
 
Thirumurugan Mylrajan
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Oliver Weikopf:
I'm not sure I understand your problem correctly. If you use only one RA file (like I do), you'll definitely have to make sure that no two methods are called synchronously, as inside a method, you'll probably set the file pointer to a position and the read or write there. This is something you can't allow two threads to do at the same time. So, synchronizing your Data methods would be necessary, no matter whether RAFile is thread safe or not.



What you mentioned is exactly the problem I would like to solve.And I want to avoid synchronization in the data methods. So I am trying to add one RAF per method so that they dont interfere with each other.

Is this an overkill compared to synchronization?..
 
Thirumurugan Mylrajan
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Daniel Dalton:
Alternatively, if you choose to create a new RandomAccessFile object per method, you need to be aware that the number of FileDescriptors available within the system is Operating System dependant - or at the very least not unlimited. That means two things:

1) You may run out of FileDescriptors (which may or may not be acceptable to you).

2) This will probably happen with different numbers of users depending on the underlying OS.

However, if neither thing happens before having an unrealistic number of users, you may be happy to accept the limitation and just document your choices.




Thank you..I never considered about this. I guess its not very high in a Windows environment. Since I want to put an end to my SCJD quest by next weekend, I would rather mention this in my choices.txt.
 
Thirumurugan Mylrajan
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mihai Radulescu:
Hi, Thirumurugan

1.Why you use FileChannel I don't think that nio is allowed.
2.You can use only one (synchronized) RAF for all your clients.
3.You can also use more than one RAFs but you need to find a way to synchronize
them, thats why the solution from 2 is easy/better.

Regads M.



Thanks all of you for your replies.

1. The FileChannel is present inside RAF.. anyway I dont know nio..
2. I dont quite understand by synchronized RAF.. I dont know how to do it.. maybe you meant synchronized data methods?.
3. Since all the file modificaion operations are controlled by lock manager I dont think it is necessary to sync RAF operations during read..
 
get schwifty. tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic