• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Thread Implementation  RSS feed

 
Prerana Verma
Greenhorn
Posts: 5
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Is it possible to create a thread without extending Thread class or implementing Runnable interface nor using anonymous inner class ??

 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prerana Verma wrote:

Is it possible to create a thread without extending Thread class or implementing Runnable interface nor using anonymous inner class ??




Can you give us the reason for such a request? Seems like a arbitrary restriction to me.


Regardless, I guess one option would be to use one of the services returned by java.util.concurrent.Executors -- but of course, under the hood, those service classes will create threads using the Thread class.

Henry
 
Prerana Verma
Greenhorn
Posts: 5
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanku for replying...

It’s just a java beginner’s query. I was trying to implement that but didn’t find any way (Found one by using anonymous class).
Just wanted to know if there is any other way of doing this.
 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prerana Verma wrote:Thanku for replying...

It’s just a java beginner’s query. I was trying to implement that but didn’t find any way (Found one by using anonymous class).
Just wanted to know if there is any other way of doing this.


How does an anonymous class allow you to do that?
 
Tim Cooke
Marshal
Posts: 4048
239
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry makes an excellent point. Under what circumstances would you ever want or need to do this?

Even as a "java beginner's query" it makes no sense to me. Thread and Runnable are there for the sole purpose of making it easy for you to create concurrent functionality in your application and there is no need to do it any other way.

Let's say you did find some crazy obscure way to do it. If you ever implemented it in a team development environment you would become very unpopular very quickly. Maintenance of that code would be near impossible.
 
Prerana Verma
Greenhorn
Posts: 5
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Saifuddin Merchant : By Creating anonymous class for Runnable or Thread.

@Tim Cooke: I'm agree with you. and I'm also not going for that complex code.

but here my question was.. "Is it possible to create...."
n was expecting a answer either Yes or No, n just a justification for that..
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Likes 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sometimes the best answer to a question is Mu
 
Heena Agarwal
Ranch Hand
Posts: 262
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prerana Verma wrote:Thanku for replying...


Prerana Verma wrote:but here my question was.. "Is it possible to create...."
n was expecting a answer either Yes or No, n just a justification for that..


As a side note, please UseRealWords while posting.

By the way, you still haven't answered Henry's question.
 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:Sometimes the best answer to a question is Mu


Learned (learnt) something new and useful
 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prerana Verma wrote:@Saifuddin Merchant : By Creating anonymous class for Runnable or Thread.



At the end of the day your still using Runnable or Thread.

So an answer to your question "Is it possible to create...." is No. Whatever you do you will be either extending Thread or implementing Runnable either directly or indirectly.
 
Prerana Verma
Greenhorn
Posts: 5
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Heena Agarwal wrote:

As a side note, please UseRealWords while posting.

By the way, you still haven't answered Henry's question.


Thank you, I'll keep that in my mind....next time..

By the Way......Reread my post!


 
Prerana Verma
Greenhorn
Posts: 5
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Saifuddin Merchant wrote:
Prerana Verma wrote:@Saifuddin Merchant : By Creating anonymous class for Runnable or Thread.



At the end of the day your still using Runnable or Thread.

So an answer to your question "Is it possible to create...." is No. Whatever you do you will be either extending Thread or implementing Runnable either directly or indirectly.


Thankyou..
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!