HTTP Connection thread doesn't update result inside TimerTask - BlackBerry Java -
i'm doing http call ksoap within timertask can update data every 5 minutes. after getting data web service provide them interface via function procecssdata(). works out first time, although timer firing every time data stays same. in fact, ui being drawn every 5 minutes uses data first http call. have idea why might happen? seems me variables inside httpcall() function not being updated.
public class connectionthread extends thread { soapobject request; soapobject result; soapserializationenvelope envelope; string[][] resultarray; int resultlength; public connectionthread(connectioncallback concallback) { callbackobj = concallback; refreshtask = new timertask() { public void run() { httpcall(); } }; new timer().schedule(refreshtask, 0, 50000); } public void httpcall() { request = new soapobject(servicenamespace, methodname); result = null; envelope = new soapserializationenvelope(soapenvelope.ver11); envelope.setoutputsoapobject(request); http = new httptransport(serviceurl); try { http.call(soapaction, envelope); result = (soapobject) envelope.getresponse(); resultlength = result.getpropertycount(); } catch (final interruptedioexception ex) { dialog.alert("no internet connection!"); _isconnected = false; } // other catch blocks { http.reset(); } resultarray = new string[resultlength][resultlength * 8]; // put result own stringarray if (_isconnected) { callbackobj.processdata(resultarray, resultlength); } } }
any soo appreciated! :) cheers, musipoo
in first place i'd advise not extend thread
unless need override custom threading behavior (that not case , scary thing do). instead, the recommended approach implement runnable
, pass thread
constructor. in javase have introduced new executors framework gets rid of instantiating threads old way. timers it's similar here implement timertask
pretty runnable
(inherits it), , schedule it.
another issue code starts thread within constructor, dangerous thing do, because every new instance created spawn new thread (the 1 asociated timer). considered antipattern. never this, , if do, please document , make sure using class know it. (more info here). confusing class extending thread launches timer in constructor, , doesn't override run
(what inheritance for?).
these tips make code clearer , bit safer, won't fix problem. think problem might in updating result
variable not putting resultarray
(or maybe ommited code?).
Comments
Post a Comment