简体   繁体   English

在线程内调用同步的(this)

[英]Calling synchronized(this) inside thread

I'm learning concurrent programming and wondering if I can call synchronized(this) on a part of a code inside threads.我正在学习并发编程,想知道是否可以在线程内的一部分代码上调用sync(this)。

I have one method which is running concurrently multiple times and I need to write to a file.我有一种方法可以同时运行多次,并且需要写入文件。 Can I use synchronize inside the method?我可以在方法内部使用同步吗?

I'm learning concurrent programming and wondering if I can call synchronized(this) on a part of a code inside threads.我正在学习并发编程,想知道是否可以在线程内的一部分代码上调用sync(this)。

I have one method which is running concurrently multiple times and I need to write to a file.我有一种方法可以同时运行多次,并且需要写入文件。 Can I use synchronize inside the method?我可以在方法内部使用同步吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 IllegalMonitorStateException在其run方法内部的线程上调用wait()(无同步块) - IllegalMonitorStateException calling wait() on a thread inside its run method (with no synchronized block) 从Java中同一类的另一个同步方法内部创建的新线程中调用同步方法 - Calling a synchronized method from a new thread created inside another synchronized method of the same class in Java 在同步方法内的线程中同步块会发生什么? - What would happen with a synchronized block in a thread which is inside a synchronized method? java - 在等待时从内部调用synchronized方法 - java - calling synchronized method from inside synchronized while waiting 从非同步方法内部调用同步 - Calling a synchronized from inside a non-synchronized method 在同步块内执行新线程 - Execution of new thread inside a synchronized block 从Java中的synchronized上下文调用Thread.sleep() - calling Thread.sleep() from synchronized context in Java 调用同步方法时线程调用非同步实例方法 - Thread calling non-synchronized instance method when a synchronized method is called 我们可以将线程连接方法放入同步方法中吗 - can we put thread join method inside synchronized method 线程在同步块内崩溃时锁定会发生什么? - What happens to the lock when thread crashes inside a Synchronized block?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM