0

I have a Consumer & Producer which use BlockingQueue (ArrayBlockingQueue) with ByeBuffer elements.

putting elements into the BlockingQueue - adds a reference to the BlockingQueue. I need to use a blockingQueue which adds the element (not reference). Is is possible to do so with java blockingQueue ?

Thanks

user3668129
  • 4,318
  • 6
  • 45
  • 87
  • 2
    Java Always add reference to any collection. – Freaky Thommi Sep 02 '15 at 10:15
  • 1
    Please see this question: http://stackoverflow.com/questions/40480/is-java-pass-by-reference-or-pass-by-value on the way objects are referenced in Java – Adam Michalik Sep 02 '15 at 10:15
  • 1
    No. There is no such thing as adding an *object* in java.The things that that keep moving are references – TheLostMind Sep 02 '15 at 10:18
  • 1
    Please write more about what you are trying to achieve or what problem you try to solve. We will get a better idea of the problem then. What you wrote so far seems to be an idea for a solution rather than the problem itself. – Daniel S. Sep 02 '15 at 10:52
  • @TheLostMind At least, [not yet](http://openjdk.java.net/jeps/169). But I suspect what OP could already do in this case is use immutable objects. – biziclop Sep 02 '15 at 11:43

1 Answers1

1

It's possible, thus ugly, for you to fill the queue with clones that you and not the collection will create.

Jib'z
  • 953
  • 1
  • 12
  • 23