• 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

RAF or FileChannel

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using NIO for reads and writes in my Data class. For every read and write i synchronize on a static RAF instance.
The question is should i synchronize on RAF (as i am doing now) or the unique FileChannel it has? Currently in all my methods i use RAF.getChannel() to get the filechannel associated with the RAF. At the end of the method i am NOT closing the filechannel. If i close the filechannel at the end of the method, the next person who wants the filechannel for someother operation throws IOException.
Is there any advantage or disadvantage or any performance issues the way i am doing? Will there be any gains if i synchronize on FileChannel instead of RAF?
Arun
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
These two techniques are almost exactly equivalent in effect, as long as all the sync operations sync on the same thing, whether it's the RAF or the FileChannel (given that there's a 1-to-1 relationship between the RAF and the FileChannel). For that matter you could also sync on some other object held in a static field, provided there's a 1-to-1 relationship wiht the RAF and FileChannel. Just make sure everyone is syncong on the same object, whciever one you choose.
Personally, just for readability I would sync on whichever object you're actually using more. In this case that's probably the FileChannel. But it doesn't really matter much.
 
You save more money with a clothesline than dozens of light bulb purchases. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic