java - Inside a class extends thread. Where to put another class creation? -
I have two classes, accept class_a packets (with multi threads) Class_B to parse each received packet What I want to do, make Class_A a new thread when the new incoming packet is made and each class_It creates a class example for parsing the thread.
Public class Class_A thread {Public class_A ()}} {} Public runs void () {Class_B B = new ClassB (); B.xxxxxxx; }} I wonder if there is any difference in constructing B instance in constructor or better? Or at the beginning of class_a?
Thanks
If Class B is always running, use for the same purpose It can be done and no amendments can be made in its properties, make it a specialty of A and create its initial position on the class constructor so that classes can be avoided immediately (loss of memory and performance) without need. . Remember that every new example of such a class will not be used anymore, there is more garbage to collect GC.
In addition, do not use
extended threads a better practice, instead of
Runnable to apply so that you have more freedom in your hierarchy (I recommend reading Java effectively for quick tips like this).
Comments
Post a Comment