Are the injected classes in Java EE and Spring synchronized?Is Java “pass-by-reference” or “pass-by-value”?How do I efficiently iterate over each entry in a Java Map?Java inner class and static nested classWhat is dependency injection?What is the difference between public, protected, package-private and private in Java?How do I read / convert an InputStream into a String in Java?When to use LinkedList over ArrayList in Java?How do I generate random integers within a specific range in Java?How do I convert a String to an int in Java?Creating a memory leak with Java

Does the Crossbow Expert feat's extra crossbow attack work with the reaction attack from a Hunter ranger's Giant Killer feature?

El Dorado Word Puzzle II: Videogame Edition

Would a primitive species be able to learn English from reading books alone?

PTIJ: Which Dr. Seuss books should one obtain?

Ways of geometrical multiplication

If the only attacker is removed from combat, is a creature still counted as having attacked this turn?

How do you justify more code being written by following clean code practices?

Why does the Persian emissary display a string of crowned skulls?

Animation: customize bounce interpolation

How do I Interface a PS/2 Keyboard without Modern Techniques?

Should I warn a new PhD Student?

How do I tell my boss that I'm quitting in 15 days (a colleague left this week)

What is the meaning of the following sentence?

Personal or impersonal in a technical resume

Does Doodling or Improvising on the Piano Have Any Benefits?

Would this string work as string?

How to make money from a browser who sees 5 seconds into the future of any web page?

Do I have to know the General Relativity theory to understand the concept of inertial frame?

Why didn't Voldemort know what Grindelwald looked like?

Storage of electrolytic capacitors - how long?

Why is participating in the European Parliamentary elections used as a threat?

Overlapping circles covering polygon

Sound waves in different octaves

Quoting Keynes in a lecture



Are the injected classes in Java EE and Spring synchronized?


Is Java “pass-by-reference” or “pass-by-value”?How do I efficiently iterate over each entry in a Java Map?Java inner class and static nested classWhat is dependency injection?What is the difference between public, protected, package-private and private in Java?How do I read / convert an InputStream into a String in Java?When to use LinkedList over ArrayList in Java?How do I generate random integers within a specific range in Java?How do I convert a String to an int in Java?Creating a memory leak with Java













1















I want to have just one TCP socket that connects to another program. Every new call to my rest endpoint writes to my TCP socket. If I write a class with my TCP socket and inject it into my Controller class, will it be thread safe? or do I have to synchronize them using the synchronize keyword?



@Component
public class ViconetBuffer

private Socket socket;

private boolean connectToViconSocket()
try
socket = new Socket(DeviceAddressUtil.socketIp,DeviceAddressUtil.port);
return true;
catch (Exception ex)
ex.printStackTrace();
return false;



public void sendDataToViconSocket(String message)
try
if (!socket.isConnected())
connectToViconSocket();
else socket.getOutputStream().write(message.getBytes());
catch (Exception ex)
ex.printStackTrace();













share|improve this question
























  • what happens when you try to write a big chunk of data to TCP and hit the service again during the transfer?

    – mceviker
    Mar 7 at 3:20
















1















I want to have just one TCP socket that connects to another program. Every new call to my rest endpoint writes to my TCP socket. If I write a class with my TCP socket and inject it into my Controller class, will it be thread safe? or do I have to synchronize them using the synchronize keyword?



@Component
public class ViconetBuffer

private Socket socket;

private boolean connectToViconSocket()
try
socket = new Socket(DeviceAddressUtil.socketIp,DeviceAddressUtil.port);
return true;
catch (Exception ex)
ex.printStackTrace();
return false;



public void sendDataToViconSocket(String message)
try
if (!socket.isConnected())
connectToViconSocket();
else socket.getOutputStream().write(message.getBytes());
catch (Exception ex)
ex.printStackTrace();













share|improve this question
























  • what happens when you try to write a big chunk of data to TCP and hit the service again during the transfer?

    – mceviker
    Mar 7 at 3:20














1












1








1








I want to have just one TCP socket that connects to another program. Every new call to my rest endpoint writes to my TCP socket. If I write a class with my TCP socket and inject it into my Controller class, will it be thread safe? or do I have to synchronize them using the synchronize keyword?



@Component
public class ViconetBuffer

private Socket socket;

private boolean connectToViconSocket()
try
socket = new Socket(DeviceAddressUtil.socketIp,DeviceAddressUtil.port);
return true;
catch (Exception ex)
ex.printStackTrace();
return false;



public void sendDataToViconSocket(String message)
try
if (!socket.isConnected())
connectToViconSocket();
else socket.getOutputStream().write(message.getBytes());
catch (Exception ex)
ex.printStackTrace();













share|improve this question
















I want to have just one TCP socket that connects to another program. Every new call to my rest endpoint writes to my TCP socket. If I write a class with my TCP socket and inject it into my Controller class, will it be thread safe? or do I have to synchronize them using the synchronize keyword?



@Component
public class ViconetBuffer

private Socket socket;

private boolean connectToViconSocket()
try
socket = new Socket(DeviceAddressUtil.socketIp,DeviceAddressUtil.port);
return true;
catch (Exception ex)
ex.printStackTrace();
return false;



public void sendDataToViconSocket(String message)
try
if (!socket.isConnected())
connectToViconSocket();
else socket.getOutputStream().write(message.getBytes());
catch (Exception ex)
ex.printStackTrace();










java dependency-injection






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 7 at 3:25







Sagar Nair

















asked Mar 7 at 3:01









Sagar NairSagar Nair

538




538












  • what happens when you try to write a big chunk of data to TCP and hit the service again during the transfer?

    – mceviker
    Mar 7 at 3:20


















  • what happens when you try to write a big chunk of data to TCP and hit the service again during the transfer?

    – mceviker
    Mar 7 at 3:20

















what happens when you try to write a big chunk of data to TCP and hit the service again during the transfer?

– mceviker
Mar 7 at 3:20






what happens when you try to write a big chunk of data to TCP and hit the service again during the transfer?

– mceviker
Mar 7 at 3:20













1 Answer
1






active

oldest

votes


















0














No, that's your job. Spring/CDI/EJB can not know how you want the several threads to coordinate their use of the Socket.






share|improve this answer























  • So should I not inject the class and make the methods synchronized and the socket static?

    – Sagar Nair
    Mar 7 at 3:39










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55035382%2fare-the-injected-classes-in-java-ee-and-spring-synchronized%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














No, that's your job. Spring/CDI/EJB can not know how you want the several threads to coordinate their use of the Socket.






share|improve this answer























  • So should I not inject the class and make the methods synchronized and the socket static?

    – Sagar Nair
    Mar 7 at 3:39















0














No, that's your job. Spring/CDI/EJB can not know how you want the several threads to coordinate their use of the Socket.






share|improve this answer























  • So should I not inject the class and make the methods synchronized and the socket static?

    – Sagar Nair
    Mar 7 at 3:39













0












0








0







No, that's your job. Spring/CDI/EJB can not know how you want the several threads to coordinate their use of the Socket.






share|improve this answer













No, that's your job. Spring/CDI/EJB can not know how you want the several threads to coordinate their use of the Socket.







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 7 at 3:33









meritonmeriton

53k1382145




53k1382145












  • So should I not inject the class and make the methods synchronized and the socket static?

    – Sagar Nair
    Mar 7 at 3:39

















  • So should I not inject the class and make the methods synchronized and the socket static?

    – Sagar Nair
    Mar 7 at 3:39
















So should I not inject the class and make the methods synchronized and the socket static?

– Sagar Nair
Mar 7 at 3:39





So should I not inject the class and make the methods synchronized and the socket static?

– Sagar Nair
Mar 7 at 3:39



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55035382%2fare-the-injected-classes-in-java-ee-and-spring-synchronized%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved