Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why can't close the remote data?

 
ZhiYuan Lin
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • 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!
 
Ta Ri Ki Sun
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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.
 
Christian Garcia
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • 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
  • 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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic