English 中文(简体)
利用监测 进入:如何使用同步方法?
原标题:Using MonitorEnter : How should i call synchronised method?
void Java_Package_Multithreading_againCallReadFile
  (JNIEnv *env, jobject obj) {

 if((*env)->MonitorEnter(env,obj) == JNI_OK) {
   printf("Now you can call the synchronised method !");
 } else {
     printf("oops ! Failed to acquire the lock.");
   }
}

从上述方法来看,如果我能够把同步使用并且可以由另一个透镜使用的方法叫作检查。 <代码>MonitorEnter 实际检查。 我阅读了文件,但没有理解文件内容。 想做的是,在检查是否安全使用这种方法后,采用同步的方法。 上述方法似乎并不正确,因为即使符合<代码>>>>><>>>/代码>的说明,我也存在致命错误。

问题回答

"What i want to do is, call that synchronised method after checking if it is safe to call that method."

这没有任何意义。 只是说了。 如果这种方法已经同步进行,你就没有增加任何价值。 电话监测 如果能够安全地采用这种方法,就进行笔录检查。 它声称你提供的物体上锁。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签