Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2006

Tip: Looking for answers? Try searching our database.

Create Thread...

Thread view: 
yffaria - 12 May 2006 13:40 GMT
Its possible create a class extended by thread and in this class, to
instance other class extended by thread too?

What problems I found when I do that?

How to create more functions of thread class in class extended by
threads?

Thx!
Robert Klemme - 12 May 2006 14:43 GMT
> Its possible create a class extended by thread and in this class, to
> instance other class extended by thread too?
[quoted text clipped - 3 lines]
> How to create more functions of thread class in class extended by
> threads?

You can't insert a class into the inheritance hierarchy after the fact.
   You could do that in Ruby though...

You can either implement Runnable and let all other Runnables inherit
that or inherit Thread and make your thread classes inherit that.

Regards

    robert
Shin - 12 May 2006 15:51 GMT
> Its possible create a class extended by thread and in this class, to
> instance other class extended by thread too?
[quoted text clipped - 3 lines]
> How to create more functions of thread class in class extended by
> threads?

I'd like to see the context of this question; it might be interesting.
But in Java language, you can not insert a layer in between exsiting
class hierarchy;  with some tools, though, you can do that

-Shin
yffaria - 13 May 2006 13:33 GMT
The context is: I have one class (not thread class), and in this class
I have two class extended by thread. In one of the thread class, I have
on method that I open one file and write something, and this is do by
the other class thread. I need do this by one thread. So when I
initialize my other thread all happen normaly, but after when I start
the thread, nothing happen.

Are you understand me?
Matt Humphrey - 13 May 2006 16:41 GMT
> The context is: I have one class (not thread class), and in this class
> I have two class extended by thread. In one of the thread class, I have
[quoted text clipped - 4 lines]
>
> Are you understand me?

It's definately a challenge for me.  You say that you have a class extended
by Thread, which means (to me, at least) that you have somehow made the
system java.lang.Thread class extend (subclass) your class.  This is
extremely unlikely.  I am more likely to believe there is a language problem
and that you really have a class that contains two objects whose classes
extend (are subclasses of) Thread. One thread opens a file and writes.

Overally, I'm still really not sure what you're asking.  My questions to you
(to help you better) are:

Do you mean extends and not extended by?
Do you really need to extend Thread at all instead of supplying a Runnable?
Why do you think you need to have a thread that starts other threads?
What do you really want these threads to do?

Cheers,
Matt Humphrey matth@ivizNOSPAM.com http://www.iviz.com/
yuriff@gmail.com - 15 May 2006 12:49 GMT
My File.java is:

class File{
 public File(int poolSize){
   //start poolSize threads of the PoolThreads
 }

 private final class PoolThreads extends Thread{
   public void run(){
     ...
     exec(some parameters);
     ...
   }
   private int exec(some parameters){
     ...
     new ProcThread().start();
     ...
   }
 }

 public class ProcThread extends Threads{
   ...
 }
}

What was wrong with him?
Matt Humphrey - 16 May 2006 03:01 GMT
> My File.java is:
>
[quoted text clipped - 22 lines]
>
> What was wrong with him?

Well, this answers the first question in that you have classes that extend
Thread.   It certainly is possible to have a thread that instantiates
another thread.  This brings us to the question of whether doing so solves
the problem.  I guess you are trying to make a thread pool, but it would
really help if you could say what you want this to do.  A thread pool is not
a kind of thread itself, so it is probably not meaningful to have it extend
Thread. In addition, there are some well-known techniques for this--see
these links.

http://www.informit.com/articles/article.asp?p=30483&rl=1

http://www-128.ibm.com/developerworks/library/j-jtp0730.html

Also the latest versions (1.5) of Java appear to include a ThreadPool
system.  I havn't used these, but look for "ThreadPoolExecutor" and you will
probably save yourself a huge amount of trouble.

Cheers,
Matt Humphrey matth@ivizNOSPAM.com http://www.iviz.com/ 


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.