• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java Thread Implementation

 
Greenhorn
Posts: 5
Netbeans IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ??

 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 5555
326
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Rancher
Posts: 43081
77
  • Likes 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sometimes the best answer to a question is Mu
 
Ranch Hand
Posts: 262
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Let nothing stop you! Not even this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic