@# Quotes DB     useful, funny, interesting





Google
 
Web www.quotesdb.info
Undernet  |  EFnet  |  Quakenet  |  Freenode  |  Dalnet  |  Ircnet  |  Galaxynet
Page: 1 2 3 4 5



Comments:

<0> Hi, is there a way to get the name of a method,like MyCl***.myMethod.getName() ?
<0> If I use the Method cl*** to find the name, I have to p*** it a string, like "myFunc", and the problem is, if I change the method's name, code is broken and the compiler doesnt catch it
<1> Lorraine_: You can itterate methods on a Cl***
<1> Relfection is inherently more likely to break by code changes though, so only use it if you -really- have to
<0> yeah...
<0> ok
<0> I'm trying to make a dispatcher
<0> normally in c++, you'd just have a function pointer
<0> Is there a preferred way to do this in java?
<2> google for function pointer equivalents in java?
<0> I've read you can create an object to wrap the function, but I was wondering if there were a better alternative
<2> i don't understand what "object to wrap the function" means.
<0> The technique I've read is to use an interface and implement it in every object that I want to p*** as parameters
<0> void dispather(superInterface object)
<0> object.someGeneralMethod();
<0> But the trouble is, some of my objects have more than one method



<2> someGeneralMethodDeclaredInTheInterface()
<0> yeah
<2> Lorraine_: cl***es can implement more than one interface. an interface can have more than one method declaration/definition.
<2> if you have worked with swing or awt, they have this Listener mechanism which goes in the direction.
<2> you implement the listener you are interested in, you add/register the listener somewhere, your methods get called, depending on the events.
<2> implement listener = implement the interface MouseListener for example
<0> yeah that's good
<2> http://www.improveverywhere.com/mission_view.php?mission_id=57
<0> ok but with the dispatcher, if I do this
<0> object.someGeneralMethodDeclaredInTheInterface()
<0> what if I have several method in the object that implements the interface
<0> the object will have to dispatch it again
<0> Think it'd be good to make inner cl***es in that object for each method I want to call this way?
<2> i don't understand. why should "object" not have several methods? and if it has, what then? as long as one of them is called someGeneralMethodDeclaredInTheInterface() and has been declared by the interface AND object's cl*** implements that interface - you can call that method.
<2> i think you should not use inner cl***es, except for small event handler stuff. inner cl***es do not solve really relevant problems.
<2> they are just there to spare us some typing, nothing else, and confusing a heck of confusion at that.
<2> causing, rather
<3> hi
<0> ok,but how will I be able to call different methods in "object" ? Suppose it implements the interface "run"
<3> netbeans/swing question: can i change the table model in the gui editor ?
<0> only run will get called
<2> Lorraine_: interfaces do not get called.
<0> and then I have to figure out which particular method to call from run
<0> I mean, the method run
<2> Lorraine_: you know the interface, why can't you decide which methods of that interface to call?
<3> Lorraine_ : mulithreading ?
<0> kmh: exactly...
<3> Lorraine_ : what's the exact problem ?
<2> eh, where is the relation to multithreading, Lorraine_?
<0> Clackwell: Well for example, I have an object that retrieves 2 kinds of information on a webpage, so 2 different methods.I don't know how to use an interface to call them
<2> kmh: Lorraine_ started out asking about function pointers, to which i pointed out that awt and swing use function pointer like counter parts for event handling, for example.
<0> yeah, the more general problem is multithreading
<0> that's just part of it
<0> I'm using Quartz to handle my threads
<3> Clackwell : function pointers sound like C to me
<0> So every object that I put in the thread scheduler has to implement the interface "execute"
<3> Clackwell : java p***es objects
<2> kmh: yes. still other languages can have suggested workaround or analogues to function pointers.
<2> kmh: and in java those are interfaces, typically.
<3> Clackwell : well yes though strictly speaing interfaces aren't required for that
<2> kmh: i was trying to help out with a commonly used mechanism, not split hairs, though. :>
<3> Lorraine_ : i think it is still not clear what your actual problem is
<3> Clackwell : sure - no problem
<2> yeah, esp. since multithreading has been brought up.
<3> Clackwell : i just saw the run()- post and was starting from there
<2> kmh: ha, she made that up out of the blue ;)
<2> there goes the multithreading bit again?
<3> Clackwell : shame on her
<3> Lorraine_ . so start over and explains us what your problem is :)
<0> alright alright
<4> Quartz to handle threads?
<4> how the hell does that work?
<3> sabre : please ...
<0> think quartz is overkill?
<3> sabre . let her start again and take it from there ...
<4> quartz is for scheduling batch jobs
<4> aight
<3> Lorraine_ : your turn
<0> one sec
<0> well before I delve, can't quartz also be used to manage threads?



<0> I'm still thinking about including it in my project
<3> Lorraine_ : forget about quartz, just state your problem
<3> Lorraine_ : and keep in mind you're in the java domain
<0> ok
<0> I have a GUI that gives the options to run several type of searches on the net
<0> Each search type is a checkbox
<0> So when the user click the search button, I want the correct function to run for every checkbox, with some parameter
<0> For now it's just a bunch of ugly if (someCheckbox.isSelected()) run somefunction
<3> Lorraine_ : well you can use a map to maje it look more sophisticated
<0> and some search types can be slow, so I want each to have its own thread
<0> Yeah that's what I was thinking
<3> maje = make
<0> But the thread problem seems harder
<0> If I use quartz, there's an "execute" method to implement
<3> just create a thread for each search
<3> so far ic no need to use quartz at all
<0> if I do it manually, there's gonna be a "run" method, so same problem
<3> why brinnging in some enterprise api not being required at all
<0> I've never done threads, so I thought quartz would simplify it
<3> Lorraine_ : definitely not imho
<1> oooh.. slick variable rename refactoring in IDEA 6..
<2> Lorraine_: i fully agree with kmh.
<4> i've never heard of anyone using quartz for threads
<0> kmh: regardless of quartz, I'm stuck with the same problem: one method will get called in my search objects, but some of them have more than one
<5> sabre: ...
<2> with lack of java language basics no third party lib is going to make anything easier for you.
<0> k
<4> sup jottinger
<3> Lorraine_ : just create a thread for each selected box
<2> yeah, keep it simple
<3> Lorraine_ : and p*** the different serach data to the thread constructor
<3> in the run method you can access the data that was p***ed to the constructor
<0> and if one search object has several methods, how do I figure it out from the run method?
<0> I mean, figure out which to call
<3> Lorraine_ : well each method can have its own thread
<3> Lorraine_ : you don't call the run() but start() (which calls run)
<3> Lorraine_ : how much do you know about threads at this point ?
<0> not that much
<0> I know the theory, i've just never coded it
<3> Lorraine_ : well read the thread part of the java tutorial, after that things might become clear
<0> yeah, I did
<0> but yeah, run gets called
<0> but I can't figure out how to create a thread for each method
<0> I can if every object has one method
<0> But if they have several..
<0> If they have one, I just create the object and the run method will do everything
<6> good morning everyone
<3> the task itsself doesn't look to complicated to me (aside from possible synchronzation issues for search completion, but you might keep it simple first)
<0> Yeah, nothing too fancy for now, just looking for reasonable speed
<0> I'll give you an example :
<3> Lorraine_ : if one object needs to call several methods - you either call several methods from run (i.e. executing them sequentially in 1 thread) or you create different threads
<0> I have an object Netcraft with 2 methods : domainInfo() and ipInfo()
<0> So I can create a thread with a new NetCraft object
<0> but when I get to the run method, I can't call domainInfo() and ipInfo() sequentially, I have to call them depending on what the user chose
<0> I'm thinking, I could make a domainInfo and IpInfo object, and derive them from NetCraft
<0> but that seems awkward
<0> I'd have to make a new cl*** for every method
<3> so use a flag
<3> one thread cl*** is sufficient, you just need to p*** the required info (a flag for instance) to the thread constructor
<2> Lorraine_: MyThreadThatCanDoEverything t = new MyThreadThatCanDoEverything(); t.doThisOneThing(hereAreTheParameters); t.start();
<3> the run method then uses the data to determine what to do
<3> actually you shorten Clackwell's suggestion tto : MyThreadThatCanDoEverything t = new MyThreadThatCanDoEverything(hereAreTheParameters); t.start();
<2> kmh: and p*** what to do in the parameters? naw, that's too abstract.
<3> Lorraine_ : not that you have only one cl*** but any many different instances (i.e. threads running in parallel) as you want
<2> Lorraine_: MyThreadThatCanDoEverything t = new MyThreadThatCanDoEverything(); t.configureToDoThisOneThing(hereAreTheParametersForThisOneThing); t.start();
<3> Clackwell : well i mean you don't need an additional method , the constructor should be fine
<2> Task myTask = new TaskXYZ(taskXYZParameters); Thread t = new Thread(myTask); t.start();
<2> kmh: then you need to encode the information of what to do in the parameters. that is what i meant as more abstract. there is no harm in being more explicit and obvious in my opinion.
<2> some people are afraid to add (more) methods to their code.
<2> maybe they have seen horrors that i haven't, yet. :)
<2> Thread theThread = null; Task theTask = null; if (xyz) { theTask = new TaskXYZ(taskXYZParameters); } if (theTask != null) { theThread = new Thread(myTask); t.start(); }
<3> Clackwell : yes and no
<3> Clackwell : doing it with a separate method less abstract (i agree), but possibly more error proned as design (for usage)
<2> kmh: calling methods is more error prone? how is that?


Name:

Comments:

Please enter the result of the sum 63 + 46 (to avoid spam):






Return to #java
or
Go to some related logs:

#AllNiteCafe
PVDASM
#linux
colac mariana
pskolog
#linuxhelp
#linuxhelp
chat serpski
oscar dirlewanger
#linuxhelp



Home  |  disclaimer  |  contact  |  submit quotes