• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

why can't close the remote data?

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
I have a exception when I use junit to test my project.the remote data can't close! But at the same time ,the local data can close .
the exception is :NullPointerException
class Data {
//..........
public synchronized void close() throws IOException {
db.close();
db = null;
}
class RemoteData {
//.......
public void close() throws IOException {
data.close();
}
class DataTest {
//.......
protected void tearDown() throws Exception {
super.tearDown();
data.close();
}
it is so simple ,where error?I think it should work! why throw NullPointerException?i just don't know how to find it out
help!
 
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can I ask why you want remote objects to close the connection ?
I may be wrong in the way I implemented it but my remote clients cant close my db connection, to shut down remote server you have to use [CTRL+C] where its running, then the database file will be closed properly, but only local connections will close the database before exiting.
 
ZhiYuan Lin
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you for your reply!
why?
o , there is a close () in my Interface ,so ..
maybe u are right it is unuseful.but why it throw NullPointerException? why can't close the database file with remote clients?
 
Ta Ri Ki Sun
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by ZhiYuan Lin:
thank you for your reply!
why?
o , there is a close () in my Interface ,so ..
maybe u are right it is unuseful.but why it throw NullPointerException? why can't close the database file with remote clients?


ah, I dont have that close in my interface, but I made it available nonetheless, anyhat, just because your instructions say you must provide this method doesn't mean you must actually close the database when the client exits.
my remote clients will get a message telling them other clients may still be active, so their request to shut down is effectively ignored.
as for why it throws a NullPointer, you'll have to show me the line number in your code where it happens for me to give you feedback on that, the code you provided doesn't say much, and one class makes a call to super but doesn't extend any other class, and the method tearDown is not in Object so instead of trying figure out whats going I'd rather you post the line number the error occurs and the code at that line.
 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm guessing that by the time you call the close method you're remote object has already fallen out of scope and has been garbage collected. You can test this by implementing the Unreferenced inteface. Add code to the unreferenced function to handle any cleanup you may need to do.
Just a suggestion.
 
ZhiYuan Lin
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Christian
i think your are right,the remote object has already fallen out of scope.
for if i just test the close() :
public void testClose() throws Exception {
data.close();
}
it is OK.

hi Ta Ri Ki Sun
class Data {
//..........
public synchronized void close() throws IOException {
db.close(); //here throw.......
db = null;
}
and the super.tearDown() is the method of junit.framework.TestCase
thank you

 
sunglasses are a type of coolness prosthetic. Check out the sunglasses on this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic