You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Benedikt Ritter <be...@gmail.com> on 2015/04/12 13:14:29 UTC

[LANG] Add ThreadUtils

Hi,

there is currently a discussion on github about the addition of a low level utility class which helps to retrieve Threads [1]. The latest proposal is to implement a predicate based approach for filtering threads [2]. My opinion is, that we should not add such an API at all, because we would have to revert it anyway, when we upgrade [lang] to Java 8. Further more I don't think it is a good idea to add a generic Pedicate interface to [lang]. This will only cause confusion for users already using Java 8. So if we really want to add predicate based API in ThreadUtils, it should IMHO Look like this:

Collection<Thread> ThreadUtils.findThreads(ThreadPredicate filter)

public interface ThreadPredicate {
   boolean test(Thread);
}

Later we can change this to:

Collection<Thread> ThreadUtils.findThreads(java.util.function.Predicate<Thread> filter)

public interface ThreadPredicate extends java.util.function.Predicate<Thread>

I'd like to hear what others think about this.

Regards,
Benedikt

[1] https://github.com/apache/commons-lang/pull/61
[2] https://github.com/salyh/commons-lang/pull/1

Send from my mobile device
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [LANG] Add ThreadUtils

Posted by Peter Ansell <an...@gmail.com>.
On 12 April 2015 at 21:26, Benedikt Ritter <be...@gmail.com> wrote:
>
>
> Send from my mobile device
>
>> Am 12.04.2015 um 13:19 schrieb Kristian Rosenvold <kr...@apache.org>:
>>
>> If think later (in 2025 :-) you just make interface ThreadPredicate
>> extend java.util.function.Predicate.
>
> Well, isn't that exactly what I suggested? :o)

There is no need to change the interface or any call signatures. Ie,
it can stay as ThreadPredicate (and already be useful by Java-8
infact). Even if it never extends java.util.function.Predicate, it is
recognised by JDK-8 as a FunctionalInterface because it only has one
abstract method. The only caveat is that it must always have one
abstract method, so it can't be updated for any Java-7 users with
other methods that they may find useful, as there won't be a default
implementation in the Java-7 interface for any new methods and it will
no longer meet the contract for FunctionalInterface.

Cheers,

Peter

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [LANG] Add ThreadUtils

Posted by Benedikt Ritter <be...@gmail.com>.

Send from my mobile device

> Am 12.04.2015 um 13:19 schrieb Kristian Rosenvold <kr...@apache.org>:
> 
> If think later (in 2025 :-) you just make interface ThreadPredicate
> extend java.util.function.Predicate.

Well, isn't that exactly what I suggested? :o)

> 
> Kristian
> 
> 
> 2015-04-12 13:14 GMT+02:00 Benedikt Ritter <be...@gmail.com>:
>> Hi,
>> 
>> there is currently a discussion on github about the addition of a low level utility class which helps to retrieve Threads [1]. The latest proposal is to implement a predicate based approach for filtering threads [2]. My opinion is, that we should not add such an API at all, because we would have to revert it anyway, when we upgrade [lang] to Java 8. Further more I don't think it is a good idea to add a generic Pedicate interface to [lang]. This will only cause confusion for users already using Java 8. So if we really want to add predicate based API in ThreadUtils, it should IMHO Look like this:
>> 
>> Collection<Thread> ThreadUtils.findThreads(ThreadPredicate filter)
>> 
>> public interface ThreadPredicate {
>>   boolean test(Thread);
>> }
>> 
>> Later we can change this to:
>> 
>> Collection<Thread> ThreadUtils.findThreads(java.util.function.Predicate<Thread> filter)
>> 
>> public interface ThreadPredicate extends java.util.function.Predicate<Thread>
>> 
>> I'd like to hear what others think about this.
>> 
>> Regards,
>> Benedikt
>> 
>> [1] https://github.com/apache/commons-lang/pull/61
>> [2] https://github.com/salyh/commons-lang/pull/1
>> 
>> Send from my mobile device
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [LANG] Add ThreadUtils

Posted by Kristian Rosenvold <kr...@apache.org>.
If think later (in 2025 :-) you just make interface ThreadPredicate
extend java.util.function.Predicate.

Kristian


2015-04-12 13:14 GMT+02:00 Benedikt Ritter <be...@gmail.com>:
> Hi,
>
> there is currently a discussion on github about the addition of a low level utility class which helps to retrieve Threads [1]. The latest proposal is to implement a predicate based approach for filtering threads [2]. My opinion is, that we should not add such an API at all, because we would have to revert it anyway, when we upgrade [lang] to Java 8. Further more I don't think it is a good idea to add a generic Pedicate interface to [lang]. This will only cause confusion for users already using Java 8. So if we really want to add predicate based API in ThreadUtils, it should IMHO Look like this:
>
> Collection<Thread> ThreadUtils.findThreads(ThreadPredicate filter)
>
> public interface ThreadPredicate {
>    boolean test(Thread);
> }
>
> Later we can change this to:
>
> Collection<Thread> ThreadUtils.findThreads(java.util.function.Predicate<Thread> filter)
>
> public interface ThreadPredicate extends java.util.function.Predicate<Thread>
>
> I'd like to hear what others think about this.
>
> Regards,
> Benedikt
>
> [1] https://github.com/apache/commons-lang/pull/61
> [2] https://github.com/salyh/commons-lang/pull/1
>
> Send from my mobile device
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [LANG] Add ThreadUtils

Posted by Oliver Heger <ol...@oliver-heger.de>.

Am 12.04.2015 um 13:14 schrieb Benedikt Ritter:
> Hi,
> 
> there is currently a discussion on github about the addition of a low level utility class which helps to retrieve Threads [1]. The latest proposal is to implement a predicate based approach for filtering threads [2]. My opinion is, that we should not add such an API at all, because we would have to revert it anyway, when we upgrade [lang] to Java 8. Further more I don't think it is a good idea to add a generic Pedicate interface to [lang]. This will only cause confusion for users already using Java 8. So if we really want to add predicate based API in ThreadUtils, it should IMHO Look like this:
> 
> Collection<Thread> ThreadUtils.findThreads(ThreadPredicate filter)
> 
> public interface ThreadPredicate {
>    boolean test(Thread);
> }
> 
> Later we can change this to:
> 
> Collection<Thread> ThreadUtils.findThreads(java.util.function.Predicate<Thread> filter)
> 
> public interface ThreadPredicate extends java.util.function.Predicate<Thread>
> 
> I'd like to hear what others think about this.

It is indeed hard to design this API in a way that is compatible with
Java 8 and earlier versions.

Providing only a findThreads() method which takes a ThreadPredicate will
not have much benefit on its own. Would we then also have to provide a
set of default predicate implementations offering the functionality that
was addressed in the original proposal?

Oliver

> 
> Regards,
> Benedikt
> 
> [1] https://github.com/apache/commons-lang/pull/61
> [2] https://github.com/salyh/commons-lang/pull/1
> 
> Send from my mobile device
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [LANG] Add ThreadUtils

Posted by Benedikt Ritter <br...@apache.org>.
Hello Hendrik,

2015-05-04 0:28 GMT+02:00 Hendrik Dev <he...@gmail.com>:

> Hi Benedikt,
>
> i have opened a new pull request
> https://github.com/apache/commons-lang/pull/78 which is based against
> the master branch, contains only a single commit and fixes the issues
> you named.
> Hope thats ok ...
>

Thank you. The PR looks very promising.

Benedikt


>
> Thanks
> Hendrik
>
> On Sun, Apr 26, 2015 at 11:40 AM, Benedikt Ritter <br...@apache.org>
> wrote:
> > Hello Hendrik,
> >
> > 2015-04-22 21:14 GMT+02:00 Hendrik Dev <he...@gmail.com>:
> >
> >> based on what i understand from this discussion i did some changes,
> >> pls see
> >>
> https://github.com/salyh/commons-lang/commit/12edd41ec7563368b03fa540af5c9a127bbfd89d
> >> for the diff and
> >>
> >>
> https://github.com/salyh/commons-lang/blob/12edd41ec7563368b03fa540af5c9a127bbfd89d/src/main/java/org/apache/commons/lang3/ThreadUtils.java
> >> for the class in its current version.
> >>
> >
> > I think we're almost there. Two minor nits remain:
> > - what's the difference between "finding" and "selecting"? I think we
> > should name all methods findXXX
> > - AlwayTruePredicate can be private
> >
> > I think if we have that we can apply the patch. Since you're an ASF
> > committer, you can add it to our svn repository yourself, if you like
> [1].
> >
> > Best regards,
> > Benedikt
> >
> > [1] http://markmail.org/message/ylmw7qzx23br4ver
> >
> >
> >>
> >> Thanks
> >> Hendrik
> >>
> >> On Wed, Apr 15, 2015 at 2:48 AM, Peter Ansell <an...@gmail.com>
> >> wrote:
> >> > On 13 April 2015 at 19:21, Benedikt Ritter <br...@apache.org>
> wrote:
> >> >> 2015-04-13 2:27 GMT+02:00 Matt Benson <gu...@gmail.com>:
> >> >>
> >> >>> +1 to what Peter said: it's a functional interface so it is
> >> >>> lambda-compatible anyway.
> >> >>>
> >> >>
> >> >> Well, yes it would be a functional interface, but it would lack all
> the
> >> >> default methods defined in java.util.function.Predicate if we don't
> >> extend
> >> >> it later.
> >> >
> >> > Agreed, I was trying to get that point across with my last comment:
> >> >
> >> >>> > > public interface ThreadPredicate extends
> >> >>> > java.util.function.Predicate<Thread>
> >> >>> >
> >> >>> > This change is useful once JDK-8 is the baseline, as it would only
> >> add
> >> >>> > features (all of the default methods) from Predicate, not remove
> any
> >> >>> > features or backwards compatibility.
> >> >
> >> > Cheers,
> >> >
> >> > Peter
> >> >
> >> > ---------------------------------------------------------------------
> >> > To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> >> > For additional commands, e-mail: dev-help@commons.apache.org
> >> >
> >>
> >>
> >>
> >> --
> >> Hendrik Saly (salyh, hendrikdev22)
> >> @hendrikdev22
> >> PGP: 0x22D7F6EC
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> >> For additional commands, e-mail: dev-help@commons.apache.org
> >>
> >>
> >
> >
> > --
> > http://people.apache.org/~britter/
> > http://www.systemoutprintln.de/
> > http://twitter.com/BenediktRitter
> > http://github.com/britter
>
>
>
> --
> Hendrik Saly (salyh, hendrikdev22)
> @hendrikdev22
> PGP: 0x22D7F6EC
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>


-- 
http://people.apache.org/~britter/
http://www.systemoutprintln.de/
http://twitter.com/BenediktRitter
http://github.com/britter

Re: [LANG] Add ThreadUtils

Posted by Hendrik Dev <he...@gmail.com>.
Hi Benedikt,

i have opened a new pull request
https://github.com/apache/commons-lang/pull/78 which is based against
the master branch, contains only a single commit and fixes the issues
you named.
Hope thats ok ...

Thanks
Hendrik

On Sun, Apr 26, 2015 at 11:40 AM, Benedikt Ritter <br...@apache.org> wrote:
> Hello Hendrik,
>
> 2015-04-22 21:14 GMT+02:00 Hendrik Dev <he...@gmail.com>:
>
>> based on what i understand from this discussion i did some changes,
>> pls see
>> https://github.com/salyh/commons-lang/commit/12edd41ec7563368b03fa540af5c9a127bbfd89d
>> for the diff and
>>
>> https://github.com/salyh/commons-lang/blob/12edd41ec7563368b03fa540af5c9a127bbfd89d/src/main/java/org/apache/commons/lang3/ThreadUtils.java
>> for the class in its current version.
>>
>
> I think we're almost there. Two minor nits remain:
> - what's the difference between "finding" and "selecting"? I think we
> should name all methods findXXX
> - AlwayTruePredicate can be private
>
> I think if we have that we can apply the patch. Since you're an ASF
> committer, you can add it to our svn repository yourself, if you like [1].
>
> Best regards,
> Benedikt
>
> [1] http://markmail.org/message/ylmw7qzx23br4ver
>
>
>>
>> Thanks
>> Hendrik
>>
>> On Wed, Apr 15, 2015 at 2:48 AM, Peter Ansell <an...@gmail.com>
>> wrote:
>> > On 13 April 2015 at 19:21, Benedikt Ritter <br...@apache.org> wrote:
>> >> 2015-04-13 2:27 GMT+02:00 Matt Benson <gu...@gmail.com>:
>> >>
>> >>> +1 to what Peter said: it's a functional interface so it is
>> >>> lambda-compatible anyway.
>> >>>
>> >>
>> >> Well, yes it would be a functional interface, but it would lack all the
>> >> default methods defined in java.util.function.Predicate if we don't
>> extend
>> >> it later.
>> >
>> > Agreed, I was trying to get that point across with my last comment:
>> >
>> >>> > > public interface ThreadPredicate extends
>> >>> > java.util.function.Predicate<Thread>
>> >>> >
>> >>> > This change is useful once JDK-8 is the baseline, as it would only
>> add
>> >>> > features (all of the default methods) from Predicate, not remove any
>> >>> > features or backwards compatibility.
>> >
>> > Cheers,
>> >
>> > Peter
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> > For additional commands, e-mail: dev-help@commons.apache.org
>> >
>>
>>
>>
>> --
>> Hendrik Saly (salyh, hendrikdev22)
>> @hendrikdev22
>> PGP: 0x22D7F6EC
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>>
>
>
> --
> http://people.apache.org/~britter/
> http://www.systemoutprintln.de/
> http://twitter.com/BenediktRitter
> http://github.com/britter



-- 
Hendrik Saly (salyh, hendrikdev22)
@hendrikdev22
PGP: 0x22D7F6EC

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [LANG] Add ThreadUtils

Posted by Benedikt Ritter <br...@apache.org>.
Hello Hendrik,

2015-04-22 21:14 GMT+02:00 Hendrik Dev <he...@gmail.com>:

> based on what i understand from this discussion i did some changes,
> pls see
> https://github.com/salyh/commons-lang/commit/12edd41ec7563368b03fa540af5c9a127bbfd89d
> for the diff and
>
> https://github.com/salyh/commons-lang/blob/12edd41ec7563368b03fa540af5c9a127bbfd89d/src/main/java/org/apache/commons/lang3/ThreadUtils.java
> for the class in its current version.
>

I think we're almost there. Two minor nits remain:
- what's the difference between "finding" and "selecting"? I think we
should name all methods findXXX
- AlwayTruePredicate can be private

I think if we have that we can apply the patch. Since you're an ASF
committer, you can add it to our svn repository yourself, if you like [1].

Best regards,
Benedikt

[1] http://markmail.org/message/ylmw7qzx23br4ver


>
> Thanks
> Hendrik
>
> On Wed, Apr 15, 2015 at 2:48 AM, Peter Ansell <an...@gmail.com>
> wrote:
> > On 13 April 2015 at 19:21, Benedikt Ritter <br...@apache.org> wrote:
> >> 2015-04-13 2:27 GMT+02:00 Matt Benson <gu...@gmail.com>:
> >>
> >>> +1 to what Peter said: it's a functional interface so it is
> >>> lambda-compatible anyway.
> >>>
> >>
> >> Well, yes it would be a functional interface, but it would lack all the
> >> default methods defined in java.util.function.Predicate if we don't
> extend
> >> it later.
> >
> > Agreed, I was trying to get that point across with my last comment:
> >
> >>> > > public interface ThreadPredicate extends
> >>> > java.util.function.Predicate<Thread>
> >>> >
> >>> > This change is useful once JDK-8 is the baseline, as it would only
> add
> >>> > features (all of the default methods) from Predicate, not remove any
> >>> > features or backwards compatibility.
> >
> > Cheers,
> >
> > Peter
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> > For additional commands, e-mail: dev-help@commons.apache.org
> >
>
>
>
> --
> Hendrik Saly (salyh, hendrikdev22)
> @hendrikdev22
> PGP: 0x22D7F6EC
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>


-- 
http://people.apache.org/~britter/
http://www.systemoutprintln.de/
http://twitter.com/BenediktRitter
http://github.com/britter

Re: [LANG] Add ThreadUtils

Posted by Hendrik Dev <he...@gmail.com>.
based on what i understand from this discussion i did some changes,
pls see https://github.com/salyh/commons-lang/commit/12edd41ec7563368b03fa540af5c9a127bbfd89d
for the diff and
https://github.com/salyh/commons-lang/blob/12edd41ec7563368b03fa540af5c9a127bbfd89d/src/main/java/org/apache/commons/lang3/ThreadUtils.java
for the class in its current version.

Thanks
Hendrik

On Wed, Apr 15, 2015 at 2:48 AM, Peter Ansell <an...@gmail.com> wrote:
> On 13 April 2015 at 19:21, Benedikt Ritter <br...@apache.org> wrote:
>> 2015-04-13 2:27 GMT+02:00 Matt Benson <gu...@gmail.com>:
>>
>>> +1 to what Peter said: it's a functional interface so it is
>>> lambda-compatible anyway.
>>>
>>
>> Well, yes it would be a functional interface, but it would lack all the
>> default methods defined in java.util.function.Predicate if we don't extend
>> it later.
>
> Agreed, I was trying to get that point across with my last comment:
>
>>> > > public interface ThreadPredicate extends
>>> > java.util.function.Predicate<Thread>
>>> >
>>> > This change is useful once JDK-8 is the baseline, as it would only add
>>> > features (all of the default methods) from Predicate, not remove any
>>> > features or backwards compatibility.
>
> Cheers,
>
> Peter
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>



-- 
Hendrik Saly (salyh, hendrikdev22)
@hendrikdev22
PGP: 0x22D7F6EC

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [LANG] Add ThreadUtils

Posted by Peter Ansell <an...@gmail.com>.
On 13 April 2015 at 19:21, Benedikt Ritter <br...@apache.org> wrote:
> 2015-04-13 2:27 GMT+02:00 Matt Benson <gu...@gmail.com>:
>
>> +1 to what Peter said: it's a functional interface so it is
>> lambda-compatible anyway.
>>
>
> Well, yes it would be a functional interface, but it would lack all the
> default methods defined in java.util.function.Predicate if we don't extend
> it later.

Agreed, I was trying to get that point across with my last comment:

>> > > public interface ThreadPredicate extends
>> > java.util.function.Predicate<Thread>
>> >
>> > This change is useful once JDK-8 is the baseline, as it would only add
>> > features (all of the default methods) from Predicate, not remove any
>> > features or backwards compatibility.

Cheers,

Peter

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [LANG] Add ThreadUtils

Posted by Benedikt Ritter <br...@apache.org>.
2015-04-13 2:27 GMT+02:00 Matt Benson <gu...@gmail.com>:

> +1 to what Peter said: it's a functional interface so it is
> lambda-compatible anyway.
>

Well, yes it would be a functional interface, but it would lack all the
default methods defined in java.util.function.Predicate if we don't extend
it later.


>
> Matt
> On Apr 12, 2015 6:49 PM, "Peter Ansell" <an...@gmail.com> wrote:
>
> > On 12 April 2015 at 21:14, Benedikt Ritter <be...@gmail.com> wrote:
> > > Hi,
> > >
> > > there is currently a discussion on github about the addition of a low
> > level utility class which helps to retrieve Threads [1]. The latest
> > proposal is to implement a predicate based approach for filtering threads
> > [2]. My opinion is, that we should not add such an API at all, because we
> > would have to revert it anyway, when we upgrade [lang] to Java 8. Further
> > more I don't think it is a good idea to add a generic Pedicate interface
> to
> > [lang]. This will only cause confusion for users already using Java 8. So
> > if we really want to add predicate based API in ThreadUtils, it should
> IMHO
> > Look like this:
> > >
> > > Collection<Thread> ThreadUtils.findThreads(ThreadPredicate filter)
> > >
> > > public interface ThreadPredicate {
> > >    boolean test(Thread);
> > > }
> >
> > In my Java-8-only code, the above is what I already do. The only
> > addition once you get to Java-8 as a baseline would be to add
> > @FunctionalInterface as a class annotation, to enable the compiler to
> > verify that it stays as a functional interface.
> >
> > > Later we can change this to:
> > >
> > > Collection<Thread>
> > ThreadUtils.findThreads(java.util.function.Predicate<Thread> filter)
> >
> > It is completely unnnecessary to make the change above, although with
> > the change below it should not disturb any code that was already using
> > it due to the way lambda matching works.
> >
> > > public interface ThreadPredicate extends
> > java.util.function.Predicate<Thread>
> >
> > This change is useful once JDK-8 is the baseline, as it would only add
> > features (all of the default methods) from Predicate, not remove any
> > features or backwards compatibility.
> >
> > Cheers,
> >
> > Peter
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> > For additional commands, e-mail: dev-help@commons.apache.org
> >
> >
>



-- 
http://people.apache.org/~britter/
http://www.systemoutprintln.de/
http://twitter.com/BenediktRitter
http://github.com/britter

Re: [LANG] Add ThreadUtils

Posted by Matt Benson <gu...@gmail.com>.
+1 to what Peter said: it's a functional interface so it is
lambda-compatible anyway.

Matt
On Apr 12, 2015 6:49 PM, "Peter Ansell" <an...@gmail.com> wrote:

> On 12 April 2015 at 21:14, Benedikt Ritter <be...@gmail.com> wrote:
> > Hi,
> >
> > there is currently a discussion on github about the addition of a low
> level utility class which helps to retrieve Threads [1]. The latest
> proposal is to implement a predicate based approach for filtering threads
> [2]. My opinion is, that we should not add such an API at all, because we
> would have to revert it anyway, when we upgrade [lang] to Java 8. Further
> more I don't think it is a good idea to add a generic Pedicate interface to
> [lang]. This will only cause confusion for users already using Java 8. So
> if we really want to add predicate based API in ThreadUtils, it should IMHO
> Look like this:
> >
> > Collection<Thread> ThreadUtils.findThreads(ThreadPredicate filter)
> >
> > public interface ThreadPredicate {
> >    boolean test(Thread);
> > }
>
> In my Java-8-only code, the above is what I already do. The only
> addition once you get to Java-8 as a baseline would be to add
> @FunctionalInterface as a class annotation, to enable the compiler to
> verify that it stays as a functional interface.
>
> > Later we can change this to:
> >
> > Collection<Thread>
> ThreadUtils.findThreads(java.util.function.Predicate<Thread> filter)
>
> It is completely unnnecessary to make the change above, although with
> the change below it should not disturb any code that was already using
> it due to the way lambda matching works.
>
> > public interface ThreadPredicate extends
> java.util.function.Predicate<Thread>
>
> This change is useful once JDK-8 is the baseline, as it would only add
> features (all of the default methods) from Predicate, not remove any
> features or backwards compatibility.
>
> Cheers,
>
> Peter
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

Re: [LANG] Add ThreadUtils

Posted by Peter Ansell <an...@gmail.com>.
On 12 April 2015 at 21:14, Benedikt Ritter <be...@gmail.com> wrote:
> Hi,
>
> there is currently a discussion on github about the addition of a low level utility class which helps to retrieve Threads [1]. The latest proposal is to implement a predicate based approach for filtering threads [2]. My opinion is, that we should not add such an API at all, because we would have to revert it anyway, when we upgrade [lang] to Java 8. Further more I don't think it is a good idea to add a generic Pedicate interface to [lang]. This will only cause confusion for users already using Java 8. So if we really want to add predicate based API in ThreadUtils, it should IMHO Look like this:
>
> Collection<Thread> ThreadUtils.findThreads(ThreadPredicate filter)
>
> public interface ThreadPredicate {
>    boolean test(Thread);
> }

In my Java-8-only code, the above is what I already do. The only
addition once you get to Java-8 as a baseline would be to add
@FunctionalInterface as a class annotation, to enable the compiler to
verify that it stays as a functional interface.

> Later we can change this to:
>
> Collection<Thread> ThreadUtils.findThreads(java.util.function.Predicate<Thread> filter)

It is completely unnnecessary to make the change above, although with
the change below it should not disturb any code that was already using
it due to the way lambda matching works.

> public interface ThreadPredicate extends java.util.function.Predicate<Thread>

This change is useful once JDK-8 is the baseline, as it would only add
features (all of the default methods) from Predicate, not remove any
features or backwards compatibility.

Cheers,

Peter

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org