multithreading - Dialog wait for download and thread issuse -
i'm trying display dialog when user attempts download something, when dialog dismissed, app redirects earlier form page. download works next form not; keeps displaying 'loading' dialog , returning previous form.
the looping form commented out of code below..
connectionrequest request = new connectionrequest(); // infiniteprogress ip = new infiniteprogress(); // dialog dlg = ip.showinifiniteblocking(); // request.setdisposeoncompletion(dlg); hashtable param_data_url = new hashtable(); param_data_url.put("index", 0); param_data_url.put("rango", 10); param_data_url.put("ciudad_id", constants.codigociudadactual); string urlbusqueda = constants.url_servicio_show_productos_adom_movil; string url_conexion = constants.geturlservicio(constants.url_servidor_aplicacion, constants.url_aplicacion, urlbusqueda, param_data_url); request.seturl(url_conexion); request.addresponselistener(new actionlistener() { public void actionperformed(actionevent evt) { networkevent netevt = (networkevent) evt; byte[] dataarray = (byte[]) netevt.getmetadata(); try { jsonparser p = new jsonparser(); inputstream = new bytearrayinputstream(dataarray); hashtable h = p.parse(new inputstreamreader(is)); enumeration enumcate = h.elements(); productodelegado prodel = new productodelegado(); imagendelegado imadel = new imagendelegado(); while (enumcate.hasmoreelements()) { hashtable aux = (hashtable) enumcate.nextelement(); enumeration enumcate2 = aux.elements(); while (enumcate2.hasmoreelements()) { hashtable aux2 = (hashtable) enumcate2.nextelement(); enumeration enumcate3 = aux2.elements(); string[] param = new string[8]; param[0] = ((hashtable) aux2.get("dompro")).get("producto_id").tostring(); param[1] = ((hashtable) aux2.get("producto")).get("nombre").tostring(); param[2] = ((hashtable) aux2.get("producto")).get("precio").tostring(); param[3] = ((hashtable) aux2.get("producto")).get("tienda_id").tostring(); param[4] = ((hashtable) aux2.get("producto")).get("calificacion").tostring(); param[5] = ((hashtable) aux2.get("imagen")).get("id").tostring(); param[6] = ((hashtable) aux2.get("producto")).get("tipo").tostring(); param[7] = "1"; try { imagen ima = new imagen(); ima.setid(param[5]); producto prod = new producto(param[0], param[1], "", param[2], "", param[4], param[3], ima, "", 0, 0, null, param[6], param[7]); if (prodel.existproducto(integer.valueof(param[0]))) { prodel.createproducto(prod); } } catch (exception ex) { system.out.println("error insertanto producto"); } string[] paramima = new string[3]; paramima[0] = ((hashtable) aux2.get("imagen")).get("id").tostring(); system.out.println(paramima[0]); paramima[1] = ((hashtable) aux2.get("imagen")).get("url").tostring(); system.out.println(paramima[1]); if(!((hashtable) aux2.get("imagen")).get("name").tostring().equalsignorecase("default.jpg")){ vector nombre = split(((hashtable) aux2.get("imagen")).get("name").tostring(), "."); paramima[2] = nombre.elementat(0).tostring() + ".thumb." + nombre.elementat(1).tostring(); }else{ paramima[2]=((hashtable) aux2.get("imagen")).get("name").tostring(); } imagen ima = new imagen(paramima[0], paramima[1], paramima[2]); try { if (imadel.existimagen(integer.valueof(ima.getid()))) { imadel.createimagen(ima); } } catch (exception ex) { system.out.println("error insertanto producto"); } } } //empieza renderizar la lista vector vect = prodel.listproddesta(); createcontainer(getresourcefilepath(), "avatarcontproddestacado"); enumeration enumpro = vect.elements(); vector vectordatos = new vector(); int = 0; while (enumpro.hasmoreelements()) { producto pro = (producto) enumpro.nextelement(); imagen imagenpro = imadel.getimagen(integer.valueof(pro.geticono_producto().getid())); hashtable dato = new hashtable(); system.out.println(pro.getid()); dato.put("urlimagen", constants.url_servidor_aplicacion + constants.url_aplicacion + imagenpro.geturl() + imagenpro.getname()); dato.put("producto_id", pro.getid()); dato.put("label2", pro.getnombre()); dato.put("label", pro.getprecio()); cmp2.additem(dato); " timeout:"+is.gettimeout() imagedownloadservice(dato.get("urlimagen").tostring(), cmp2, i, "avatar"); cmp2, i, "avatar", dato.get("producto_id").tostring(), new dimension(100, 100), imagedownloadservice.priority_critical); // networkmanager.getinstance().addtoqueue(ids); system.err.println(dato.get("urlimagen")); imagedownloadservice ids = new imagedownloadservice(dato.get("urlimagen").tostring(), cmp2, i, "avatar"); // ids.setpriority(imagedownloadservice.priority_critical); networkmanager.getinstance().addtoqueue(ids); } catch (exception ex) { system.out.println("error en la descarga de imagen imagedownloadservice.createimagetostorage"); } i++; } cmp2.repaint(); } catch (exception ex) { system.err.println("error"); } } }); networkmanager.getinstance().addtoqueue(request); } }); } return true; }
your indentation , block of code makes impossible read , cut off top of call impossible know. however, since return sort of method , return value i'm assuming logic incorrectly expects synchronous behavior addtoqueue asynchronous.
try changing addtoqueue addtoqueueandwait.
Comments
Post a Comment