Steve
Steve Luke wrote:The short answer is there are dozens of ways of making one thread wait for another thread. The question is, why doesn't wait()/notify() work for you? Knowing that will help determine which is the best route to take.
Aleksey Vladimirovich wrote:No-no, wait() is okay, the thing is to wake a thread with my own method (not notify()).
Steve
Aleksey Vladimirovich wrote:Please ignore the Vector collection (I know it's not good), unfortunately I have to deal with old java 1.4 here
Steve
Vector was bad in Java 1.4 - much better tools where available then, so this is not a good excuse for using Vector.
Jesper de Jong wrote:ArrayList and HashMap instead of Vector and Hashtable.
But since you didn't mention until now that you're working on Java ME, Steve ofcourse didn't know that you can't use those because they're not there in the library for Java ME.
Aleksey Vladimirovich wrote:Yea, I'm aware of these collections and it's a shame that they're not available in J2ME, I just thought maybe there were any alternatives of ones in J2ME.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:But Vector and Hashtable are? That would suggest to me that J2ME is many versions behind Java SE, which strikes me as a problem right there.
Winston Gutkowski wrote:
But Vector and Hashtable are? That would suggest to me that J2ME is many versions behind Java SE, which strikes me as a problem right there.
I wonder also if threading isn't a red herring here. If you want something notified of a change, my suggestion would be to implement the Observable/Observer pattern. Then you can implement any kind of notification you want.
Aleksey Vladimirovich wrote:...but if you meant "excessive" than the answer is no, I wanted to implement lazy image downloader and there is no way to do it without threading. And yes, I've used the Observer pattern here, it works fine...
but I'm still worring about memory overhead...I guess there is nothing I can do here though.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:Then I'm not quite sure what your question is. The Thread is the thing that needs to do the notification, so just register it with your Observable (presumably your cache of images) and notify it that it's complete.
Winston Gutkowski wrote:What overhead? The image itself is likely to be far bigger than anything else you need to concern yourself with.
But, as I say, maybe I'm just being thick and don't follow what your problem is.
Aleksey Vladimirovich wrote:As for images - they are sort of small logos (about 2K each) and there is nothing to do with them...I mean as a programmer I cannot save memory on them, unlike these inefficient collections, but I guess I just have to accept it.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Aleksey Vladimirovich wrote:As for images - they are sort of small logos (about 2K each) and there is nothing to do with them...I mean as a programmer I cannot save memory on them, unlike these inefficient collections, but I guess I just have to accept it.
Well, for starters, those collections are only time inefficient, because they're synchronized when there's often no need. I doubt whether there's very much difference (if any) in space efficiency between them and the newer types. The basic overhead is for the collection object itself (maybe 20-30 bytes) and a dozen or so for each element because it must be an object. Hashtables will also have an overhead for the internal bucket store; however, since each of your objects is already 2K it's likely to be a drop in the ocean.
HIH
Winston
No prison can hold Chairface Chippendale. And on a totally different topic ... my stuff:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
|