« first day (1520 days earlier)      last day (3415 days later) » 

12:01 AM
Can anyone clarify on this answer? stackoverflow.com/questions/27584832/…
I'm not sure exactly what is meant and whoever answered is offline
 
fge
@ZouZou yeah, it appears to be more of a hassle than I thought
Not insurmontable but would require a s*load of testing
 
for?
 
fge
All mapping methods
You'd have to check that the returned stream is an implementation of AutoCloseStream
Anyway, ByteStream seems more useful
 
but why would you have to do that check
you are not supposed to change the state of the stream isnt it?
or i don't get what you mean
maybe with an example
 
fge
Well, say you .filter() and return delegate.filter()
That ruins the point
You have to reassing the delegate and return this
And for a map() operation you change the generic type
So you have to return a new wrapper with delegate.map()
Bah
try-with-resources it is
(when needed)
 
12:19 AM
I see
 
12:52 AM
@fge I try to reduce your code to     map.entrySet().stream().flatMap(e -> e.getValue().stream().map(v -> Stream.of(new AbstractMap.SimpleEntry<>(e.getKey(), v)))).forEach(System.out::println);
ouch formatting
map.entrySet().stream().flatMap(e -> e.getValue().stream().map(v -> Stream.of(new AbstractMap.SimpleEntry<>(e.getKey(), v)))).forEach(System.out::println);
unfortunately i get a bunch of java.util.stream.ReferencePipeline$Head@7adf9f5f in output
dunno why
 
fge
Hmm, it seems to me that you create one Stream per entry, no?
 
yep but since I flatMap i would expect the same result as yours
 
fge
That makes for quite a lot of objects ultimately
Maybe you could use .collect(Collector.of(something)) here
 
I tried to collect them in a List<Map.Entry<String, String>> with the traidtionnal toList()
but I get
Type mismatch: cannot convert from List<Object> to List<Map.Entry<String,String>>
seems like there is a type inference weakness in the process
or I do something fundamentally wrong x)
Oh I get it
I should do another level of flatMap
map.entrySet()
                .stream()
                .flatMap(e -> e.getValue().stream().flatMap(v -> Stream.of(new AbstractMap.SimpleEntry<>(e.getKey(), v))))
                .forEach(System.out::println);
argh
 
fge
e -> e.getValue().stream().collect(Collector.of(ArrayList::new, (list, value) -> list.add(new AbstractMap.SimpleEntry<>(e.getKey(), value)), List::addAll)).stream()
Yeah but you create one Stream per created Map.Entry
That's a lot
I think coding a helper method would be better, no? ;)
This way you can use a method reference as the lambda
Because even my solution is costly
(I suspect less than yours, though)
 
1:07 AM
I'm sure we can one line this
 
fge
Why? :p
Short is not always better :p
 
I don't know ! This stream API makes me feel like everything is a one liner :D
 
fge
Eh, no, there's not yet a .doWhatIWant() method :p
 
i'll definitely switch to Scala
haha
and come back when Java 10 comes out
 
fge
I'm not a fan of terseness -- at least I don't see it as that much of a virtue
It's OK when it really makes things more understandable, but sometimes it doesn't, and that's where I set the limit
 
1:10 AM
I agree with you that Java is a pretty good language to starts with
because it forces you to write understanable code, the rules are pretty strict when we compare with other languages
that's why I like it
but I feel like it lacks some syntax constructions that would make our life more easy but that's my opinion
this is a great improvement since Java 8, I appreciate lambda, method reference and the stream API
 
user1648409
Hi, someone here who knows a bit about Java Networking and can help me a bit at a Network Scheduler i wrote in Java?
 
fge
@ZouZou what syntax constructions for instance?
@Shiuyin a scheduler? And what does it schedule?
 
user1648409
Messages sent via WebSockets
 
pattern matching for example
 
user1648409
i ocassionaly get ConcurrentModificationExceptions and i have a feeling that i did something horribly wrong. It's my first time working on network stuff so im interested in what better programmers think i should do
 
fge
1:21 AM
@Shiuyin without code it's difficult to tell; have you posted the question on SO with the relevant code?
 
operator overloading, I find it pretty useful to
 
user1648409
no i haven't posted it but i can of course pastebin it here
 
user1648409
dont laugh - it's my first try at some networking stuff ;D
 
fge
@Shiuyin you'd better ask a question, there are many more people on SO than here
@ZouZou argh, this is the kind of terseness that I find extremely confusing
 
user1648409
im more interested in what people THINK i should do in a discussion rather then simple answers "do this, do that" i want to understand the systems and logic behind it
 
1:22 AM
haha well it has its pro and cons
 
fge
@Shiuyin well OK, then paste the relevant code and let's see what comes of it
 
user1648409
 
user1648409
again: dont laugh. im in 3rd semester at medical informatics and this is my first try at networking stuff
 
why would we laugh
we are all beginners
and we all begin
don't worry
:)
 
user1648409
good :p
 
user1648409
1:26 AM
i mean - my code is working - it just crashes sometimes and i think i need to redo it completely
 
fge
@Shiuyin I'm not surprised that it can throw that exception
In your Runnable you can send() again
 
user1648409
yes because after waiting the appropriate time it still needs to send the message ^^
 
fge
If I were you I'd use a producer/consumer model
 
user1648409
whats that?
 
fge
And a PriorityQueue
Hmmm, I have some code which does something similar to that however it consumes the items definitively, it looks like you reschedule the same items
 
user1648409
1:30 AM
what i want to accomplish with my code is the following: i want to store Messages from Server -> Client in something like a quere and only throw them out via WebSockets to the client once at a time (Config.MAX_MESSAGES_TIMER)
 
user1648409
so i do not care about permanently concuming those items as long as they get sent
 
fge
So you mean to throttle message sending?
 
user1648409
yes something like that
 
user1648409
i want to reduce the network / server power needed for user X so i try to throttle those things
 
user1648409
that was my general idea, so without googling anything i wrote that NetworkScheduler class
 
fge
1:34 AM
Uhwait, do you mean to throttle the number of messages sent per unit of time globally or per user?
 
user1648409
per user
 
user1648409
(also to prevent spamming etc.)
 
fge
I believe a Semaphore is your best option then
The problem is that this class has no option to set the number of permits, only to release a certain number of them
I'm talking about this class
 
you are sure?
there is a constructor to set the number of permis
permits$
 
fge
@ZouZou yes, I know, but not to set atomically the number of permits
 
user1648409
1:37 AM
give me one second, let me have a look at that class
 
fge
For instance, say you build one with 20 permits
.available() says 10, so you .release(10)
But between .available() and .release(), someone can consume another permit
So you'd end up starving the consumers
 
user1648409
hm
 
fge
OR
You .drainPermits() (this is atomic) and .release() the number you want
You do that in the thread which controls scheduling
 
user1648409
do i generally have a logical flaw in my class i pastebin'ed?
 
ok I didn't know that
 
fge
1:40 AM
And in the consumers, you do while (true) { sem.acquire(); sendthemessage; }
 
i though it was atomic
 
fge
The scheduling thread would run at fixed timed intervals in a ScheduledExecutorService
@ZouZou as long as you have to invoke two methods it isn't atomic anymore :p
 
true enough
 
fge
@Shiuyin it's your Thread that's the problem
 
for my defense I haven't read JCIP yet :D
 
fge
1:42 AM
I didn't wait for JCIP for that, I studied the Linux kernel code :p
 
user1648409
@fge: So in generell you think Semaphore's (never heard of them) are the way to go for me and i should use those
 
hah nice one
 
fge
@Shiuyin definitely, yes
 
user1648409
@fge: a few min ago you said you have code doing nearly the same. can i have a look at that to have a cool and nice running example?
 
fge
@ZouZou you mentioned Brian Goetz earlier; I wish he took the time to write JCIP v2
@Shiuyin in fact it is different from what you want to do, it wouldn't help you
 
1:44 AM
Yeah he said he would update it to add the new stuff
 
fge
@Shiuyin in my case ordering is important so I use a PriorityQueue; but in your case this is not the same constraint
 
132
A: Is "Java Concurrency In Practice" still valid?

Brian GoetzWhile my perspective may be biased, my current intention for updating the book would be almost strictly additive, covering fork-join, parallel decomposition, and the new parallel bulk data operations coming in Java SE 8.

 
fge
@ZouZou really?
 
user1648409
@fge: Ok. Then let's talk about my general goal i want to achieve with my code. do you think that what i want to achieve is useful? good? useless?
 
user1648409
would like to hear useful opinions :D
 
fge
1:45 AM
@Shiuyin throttling is always a good thing
@ZouZou note, the answer says "my current intention is...", he didn't say he would actually do it :p
I certainly wish he did!
 
I think he has a lot of work nowadays
 
fge
@ZouZou have you seen that video yet?
A little old but still relevant
 
Noo
I see you linked it many times
 
fge
Yes :p
 
user1648409
hmm
 
user1648409
1:50 AM
Do i understand those semaphores correct, that they both work on server side and do the job of throttling via one thread with the semaphore storing the data and the other thread with the semaphore taking the data out and sending it?
 
Concerning the books, I think he will release both next year. One concerning the brand new stuff on the standard API, and one on JCIP
 
fge
@Shiuyin a semaphore will only "deliver" permits; they won't deliver useful data, this has to be done another way
@Shiuyin but they are great to guard access to the data source
@Shiuyin the idea I have in mind is that you take one permit per message to send, and when you have eaten your quota, the scheduler thread will fill it again
 
user1648409
so i can think of it as something like a "interface" to get to the data from the both threads trying to access the data. one thread adding data, the other trying to get data out and send it
 
@fge Added to my youtube playlist, I'll take a look later
alreay 3a.m
 
fge
And yes, that means that the semaphore needs to be shared by the thread sending the message and the scheduling thread
 
1:52 AM
gotta sleep
cya
 
fge
Bonne nuit!
 
user1648409
@ZouZou cu
 
merci :D
 
fge
@Shiuyin that's the idea, yes
 
user1648409
ok, one or two more questions and i will not bother you with that stuff again please :D
 
fge
1:55 AM
@Shiuyin also, use a BlockingQueue for messages; this way, if you have no messages to send, the sender thread(s) will sleep until messages to send are available
 
user1648409
Lets say we have my class NetworkScheduler. When this class is instantiated or functions of it are called that would be by thread A. So the Sleeper Thread inside NetworkScheduler would be thread B. The Data to be sent is saved inside a blockingqueue of NetworkScheduler and when thread a cant send anything because not enough time has passed it simply starts a new instance of thread b who will try to access the data via the semaphor
 
user1648409
correct?
 
fge
No, that's not how I'd do it
Hold on, brb in 5 mn
 
user1648409
ok
 
user1648409
Then i still seem to not have gotten the idea of it :D
 
fge
2:01 AM
OK, so, first, how many sender threads do you have?
 
user1648409
1
 
user1648409
there is only 1 server who has only 1 thread
 
fge
Ah, OK, I though that would be more
Well, add another thread to that
 
user1648409
the only "Thread-Thing" i currenly have is that little Sleeper Thread in NetworkScheduler
 
fge
And who produces the messages to send?
 
user1648409
2:02 AM
the server's thread itself
 
fge
Uhm, that's not the sender thread then?
 
user1648409
Hm, then maybe i did understand you wrong
 
fge
OK, my plan involves at least two threads: one to send, and one to reset the semaphore
The first would run in a classical ExecutorService, the scheduler in a ScheduledExecutorService
 
user1648409
here is what happens: my server who has only it's mainthread produces messages, instantiates NetworkScheduler once at the server startup and always calls scheduler.send() in the same mainthread. There is only one Sleeper Thread started once the send() cant compute because not enough time has passed
 
fge
OK well let's continue about the NetworkScheduler class -- it would contain those two threads I talked about
 
user1648409
2:06 AM
ok (btw do you have teamspeak or something? better for explaining a beginner like me that stuff :d)
 
fge
No, I don't even know what that is
 
user1648409
okok
 
user1648409
go on with your explanation please
 
fge
So, the sender thread would do something like this (adapt to your classes): while (true) { try { sem.acquire(); Message msg = messageQueue.take(); } catch (InterruptedException e) { break; } send(msg); }
So, it will block (and possibly be interrupted) in two situations: when acquiring a permit (if it has exceeded its quota for this period of time) and when getting a message (because there are no messages to send)
The scheduling thread would run at regular intervals and would simply to that: sem.drainPermits(); sem.release(NR_PERMITS);
That's all
 
user1648409
Then i only would have to add messages from outside to the message Queue and those 2 threads would take care of the rest. correct?
 
fge
2:12 AM
Yes
THe queue would be a BlockingQueue
(choose your implementation according to your needs)
 
user1648409
hm i think i understand the basics of it now^^
 
user1648409
implementing it is a whole other question though
 
fge
Oh, it shouldn't be too hard ;)
 
user1648409
well you know - im only in 3rd semester
 
user1648409
and stuff we do is something like html, php, css
 
user1648409
2:14 AM
im totally bored of that so i chose to choose a project and do that to keep me entertained
 
user1648409
so what i am doing here right now is far above my 3rd semesters level
 
fge
There's school education and there's your self education, the two don't have to match :p
I did systems programming while in high school
 
user1648409
hm
 
user1648409
one last question then i have to go
 
user1648409
i understand the basic concept of all that i think but i still dont understand why you would need 2 threads. one thread keep "taking" messages out of the blockingqueue. That is the sender thread who trys to send the messages. But why have a scheduling thread? What does that do? ^^
 
fge
2:18 AM
It takes care of message throttling
Say you want a maximum of 20 messages per second; you'd make that thread run every second, and reset the semaphore to 20 permits, one per message
 
user1648409
AH
 
user1648409
so the schedulerthread is executed for example once per minute and does something like
semaphore.permits = 20
 
fge
And it would run in a ScheduledExecutorService since it can .scheduleAtFixedRate(), which is what you want
 
user1648409
and because of the schedulerthread
 
user1648409
the sending thread can only send 20messages per second
 
user1648409
2:20 AM
because it has only those 20 permits
 
fge
To be precise it will sem.drainPermits() then sem.release(20)
Yes, exactly
 
user1648409
HAH
 
user1648409
understood
 
user1648409
however that will throttle all messages - i wanted it per user, so i would have to instantiate one semaphore per user? or one semaphore counter per user?
 
fge
Yes
And one thread per user
And don't be afraid, threads are cheap; way cheaper than what most people think
 
user1648409
2:22 AM
ouch, wouldn't that cause a lot of ... ok i guess not
 
user1648409
just read your answer
 
fge
Especially under Linux
 
user1648409
ok, thank you very much for your explanation!
 
fge
No problem
 
user1648409
ill try to implement it tommorrow
 
user1648409
2:24 AM
lets see if im capable of it :d
 
user1648409
thank you very much again and good night
 
user1648409
(3:30 am already...)
 
fge
Have fun ;)
 
user1648409
will most likely have some :x
 
user1648409
threads are always "fun"
 
user1648409
2:25 AM
cya !
 
Sim
what are the chances people are going to detect between letter O and number 0
for SSID
 
I am sad today
 
2:49 AM
I am not made for open source stuff
=help
 
Commands=====================
=about     Displays information about this bot.
=help      Displays this help message.
=http      Displays information about HTTP status codes and methods.
=javadoc   Displays class documentation from the Javadocs.
=shutdown  Terminates the bot (admins only).

Listeners====================
mention   Sends a reply message when someone mentions the bot's name.
 
=shutdown
 
@ItachiUchiha Only admins can shut me down.
 
=about
 
OakBot v0.0.2 by Michael | source code | built: About 2 days ago. | started up: About 2 days ago.
 
 
3 hours later…
6:03 AM
@Sim - The chances depend on the person's eyesight!
 
6:44 AM
Greetings
 
6:55 AM
Morning!
 
hey uni
So, yesterday I was trying to learn about lambda. And is it true to say that Lambda expressions work only for Functional Interfaces?
 
@Mr.777 That's essentially what Lambda expressions are. They take some input and may return something, like this:
parameters -> (return)?
 
Yes, that's what I understood. So, then I read about some built-in functional interfaces like Predicate<T>, Consumer<T> & Function<R,T>
I am really amazed by the new stuff from java8.
 
Functional Interfaces are just an interface with one and only one abstract function, which is why the lambda expressions can be typed with functional interfaces in runtime through a meta factory.
 
Okay, so how is a lambda expression more efficient than loops or other stuff like method declaration stuff?
 
7:01 AM
Because invokedynamic. It is also better than every approach, such as using inner classes.
For example, the fact that its runtime representation is not concerned in compile time reveals its legibility to be retained as a raw lambda until it has to be used, which allows free lazy conversion to an actual interface. Thus, if a lambda is never really used, it isn't generated. Free laziness + caching + boost classloader performance most of the time
That and it gets rid of a lot of abundant headers, for example, this:
personStream = personStream.filter(
    new Predicate<Person>() {
        @Override
        public boolean test(Person p) {
            return p.age > 50;
        }
    }
);
Beef to onion breakdown:
personStream = personStream.filter(
    ... (Person p) .. p.age > 50; ...
);
And with lambda expression:
personStream = personStream.filter(
    (Person p) -> p.age > 50
);
 
you can ignore data type though right?
like:
personStream = personStream.filter(
    p -> p.age > 50
);
 
If you do that, you're just forcing the compiler to do the work. It's called type inference. This won't work when the method is overloaded.
For example, ambiguous type Lambda$capture 1 when you're doing this:
 
Which method?
Oh new information :O
 
{
    Baz foo = new Baz();
    foo.bar(a -> true); // compile time error
}

class Baz {
  bar(Predicate<Baz> p);
  bar(Predicate<String> p);
}
 
Oh yes. Wow, that's really new information. Thanks
 
7:13 AM
Because the compiler won't know the type of a, so the type cannot be inferred and you end up with a broken lambda. Even if you don't specify the type, it's still generated in runtime a T t, U u -> R. You know, syntactic sugar.
 
Okay.
I now want to practice lambda expression but don't know what to do? Is there any exercises or how do you think one should practice for them?
 
Answering questions related to lambdas may be good thing to do.
 
Wow
 
I don't think anyone made decent exercises on them, though.
You could try looking for some. Let me know if you find any.
 
Sure I will let you know
Found a book named Java 8 Lambdas: Pragmatic Functional Programming but it doesn't contain exercises as well
 
 
1 hour later…
8:56 AM
0
A: Android development without using Eclipse

MariuszI recommend to NOT use any JAVA based editor (like IntelliJ Idea, Netbeans) - and on no account to use Eclipse. I develop with quite old computer - 3 GB of RAM memory, slow Intell Core 2 Duo (1600 MHz), slow HDD drive. When I worked with Android Studio (which is based on IntelliJ Idea) my com...

> Eclipse on the other hand is a total crap - totally not intuitive - and usually used by: a) JAVA programmers - which usually don't know why they are doing something (like using getters/setters), and embedded programmers - who like a mess (I work as a embedded programmer for several years and I have never seen clean embedded code) - so the Eclipse "mess" is funny for them.
 
Troll
@uni got some time for talking on javaroom.website?
 
Sure, I haven't been doing anything with it though, busy hunting for hats :)
BTW, while I'm working on the mail forwarding server, anyone want a free username@javaroom.website email?
5
 
Are you trying to built it from scratch or have you given a thought to some UI frameworks?
 
@Uni why not, i want it
 
@Unihedro lolz, hit me with one,
I want an ita@javaroom.website :P
 
9:00 AM
Email me at admin@javaroom.website with your actual mail address to forward to.
 
okay
 
It will last for as long as the domain is alive, which equals as long as I bother spending money on it, which is a long time
 
you still didn't answer my question
 
@ItachiUchiha From scratch! With the help of some PHP masters behind the scenes of course :)
 
@Unihedro Hmm, that is gonna take some time.
:D
 
9:01 AM
@Unihedro Done
 
It's... actually... java room.website
 
what? :O
admin@room.website?
 
> mr777@java.website
 
yep perfecto
 
There's a "room" in there.
 
9:05 AM
thanks @Uni for being so generous :D
 
Heya @Prashant
 
Hi
 
Hello, welcome to the room of Java!
Where your dreams may or may not come true
>_>
<_<
 
thanks :)
absolutely i will get something .. but i will not loose anything :P
 
@Prashant is that so? :P
I am waiting for @fge @Ita, any idea when will he appear in the room?
 
9:12 AM
Nope..
 
How is your work going with FailFastIterations?
 
yesterday my internet crashed and when I was back, he had completed the class I was working on n committed it.
 
lol
 
fge is in the room, just sleeping
 
7 hours ago, by ItachiUchiha
I am sad today
 
9:13 AM
no problem, you can always get new things to do, don't worry
 
No I am not
 
well atleast you learnt to use mockito, TestNG and assertj
 
I am not gonna work on something, which will I am not confident of..
and needs someone's assistance all the time
 
You get confidence by doing
 
You get confidence by learning.
 
9:15 AM
And you learn by doing ;)
 
Not only by doing, also reading interesting things :P
 
So, doing -> learning -> confidence
 
I would prefer to learn the nio API on my own
 
@Ita good luck
 
9:17 AM
BTW, good news is, i can now atleast write basic lambda expressions :P
And now I cant find exercises to practice
 
Wait until Java expands lambda expressions to Lambda Notation.
 
:P
 
Lambda calculus (also written as λ-calculus) is a formal system in mathematical logic and computer science for expressing computation based on function abstraction and application using variable binding and substitution. First formulated by Alonzo Church to formalize the concept of effective computability, lambda calculus found early successes in the area of computability theory, such as a negative answer to Hilbert's Entscheidungsproblem. Lambda calculus is a conceptually simple universal model of computation (Turing showed in 1937 that Turing machines equalled the lambda calculus in expressiveness...
I really should stop hunting for hats and do something more productive.
 
But...... hats
 
I have 22 hats already
It's Solstice day! Go make a post or comment today to earn a HAT!
 
9:28 AM
hello. someone here to give me a little help ?
 
hey guys
@George02 ask
 
so .. I have a class that extends class A
and a class that extends class B
the thing is that those classes that extends A respective B do same things
but I need to keep that extend A for having A attributes
how can I make only one class to solve this ?
reformulating :) I'm working on an android project and I have something like this
class classOne extends LinearLayout
class ClassTwo extends RelativeLayout
ClassOne and ClassTwo do the same things but I need to keep the LinearLayout and RelativeLayout on them.
and have another class that can wrap those two
 
@Mr.777 sure :)
 
9:50 AM
@George02 What do you mean "do the same things"?
 

« first day (1520 days earlier)      last day (3415 days later) »