首页 \ 问答 \ 如何在java中实现类级别锁定?(How is class level locking achieved in java?)

如何在java中实现类级别锁定?(How is class level locking achieved in java?)

我知道锁定概念与静态和非静态方法同步分别锁定类和实例。 我无法理解的是,如何实现班级锁定? 我的意思是,课程只是一个模板,没有任何物理意义。 那么,当我们说通过同步静态方法实现类级别锁定时会发生什么呢? 该类的所有对象是否被锁定或其他进程?

我可以通过搜索找到的是有类对象(Class.class)并且在此类对象上获取了锁。 但那个班级的所有实例也是如何锁定的呢?


I am aware of locking concepts with synchronization of static and non static methods to lock classes and instances respectively. What I am not able to understand is, how is class level lock achieved? I mean, class is a template only, with no physical significance. So, when we say that class level locking is achieved with synchronizing static methods what happens then? Do all the objects of that class get locked or some other process?

With what I could find out with my search is that there are class objects (Class.class) and lock is acquired on this class object. But then how are all instances of that class also locked?


原文:https://stackoverflow.com/questions/24068672
更新时间:2024-03-05 15:03

最满意答案

Model.Item == Context.Item?

正如@ Jim-Noellsch所提到的,如果您的代码基于当前上下文项运行,则默认值将与Model.Item相同。 但是,如果要构建数据源驱动的组件或使用控制器更改模型上的绑定项,则需要使用Model.Item来确保拉出绑定到模型的项,而不是上下文项。

MVC布局中的Web窗体?

至于MVC布局中的Web表单,我不相信Sitecore支持开箱即用。 您可以查看其他人为完成类似操作而做的一些自定义( Web表单中的MVC )。 从本质上讲,这归结为自定义管道以允许处理不兼容的组件。

混合Sitecore解决方案

您还可以使用Web窗体中的某些页面和MVC中的某些页面构建混合站点,但这可能需要您将某些组件从一个转换为另一个。 我最近在这里写了一篇关于混合动力车的文章: http//www.nonlinearcreations.com/Digital/how-we-think/articles/2015/05/MVC-Web-Forms-Hybrid-Sitecore.aspx

对于混合方法,如果您需要在两种布局类型上具有类似的功能,那么是的,您将需要“重复”组件(一个子布局,一个渲染)。 这完全可以接受。 您已经拥有不同的布局和模板,这只是另一层。 您可能还在子布局中放置了一些演示业务逻辑。 您可能想要考虑将其移动到ViewModel类,然后在渲染和子布局中使用相同的类

使用ViewModel

对于Model.Item,您可以指定将成为模型对象的业务对象,而不是使用模型的标准Sitecore项。 我有一个SlideShare,可以将WebForms子布局转换为MVC渲染 。 幻灯片6显示了ViewModel实现示例,幻灯片8显示了在MVC视图中使用它。 从这里开始,您可以在子布局后面使用相同的ViewModel来集中一些逻辑。


Model.Item == Context.Item?

As @Jim-Noellsch mentioned, if your code is running based on the current context item, then the default will be the same as the Model.Item. However, if you are building datasource-driven components or have altered the bound item on the model using a controller, you will want to use Model.Item to ensure you pull the item bound to the model, and not the context item.

Web Forms inside MVC layout?

As for web forms inside an MVC layout, I do not believe that Sitecore supports this out of the box. You can view some customizations that have been done by others to do something similar (MVC inside web forms). Essentially, this comes down to customizing the pipelines to allow your incompatible components to be processed.

Hybrid Sitecore solutions

You can also build a hybrid site with some pages in Web Forms and some in MVC, but this may require you to translate some of your components from one to the other. I recently wrote a post on hybrids here: http://www.nonlinearcreations.com/Digital/how-we-think/articles/2015/05/MVC-Web-Forms-Hybrid-Sitecore.aspx

For a hybrid approach, if you need to have similar functionality on both layout types, then yes, you will need 'duplicate' components (one sublayout, one rendering). This is completely acceptable. You already have different layouts and templates, this is just another layer. You may also have put some presentation business logic in your sublayouts. You may want to think about moving that to a ViewModel class and then using the same class in both your rendering and sublayout

Using ViewModel

For your Model.Item, instead of using a standard Sitecore Item for your Model, you can specify a business object that will be the model object instead. I have a SlideShare on converting WebForms sublayouts to MVC renderings. Slide 6 shows a ViewModel implementation example, and Slide 8 shows using it in an MVC View. From here, you could probably use the same ViewModel behind your sublayout to centralize some of your logic.

相关问答

更多
  • 在某些情况下,合并这两者可能会带来巨大好处。 MVC并不适合内容驱动的网站。 但是,具有结构化流程和多个数据表示的Web应用程序从中受益匪浅。 Sitecore在多个数据展示方面有一定的局限性 - 您只能在一个项目上定义一组设计细节。 如果您没有WYSIWYG编辑或轻松一键式预览的要求,则可以使用Sitecore作为数据存储库,并利用来自其管道(例如语言)的一些Context值。 Sitecore HTTP管道需要进行一些修改才能使其工作: 1)如果在IIS6中使用aspx扩展来让ASP.NET处理MVC请 ...
  • 如果我在你的位置,我会查看Sitecore的Glassmapper。 这是Sitecore相当轻量级的ORM。 http://www.glass.lu/Mapper/Sc 我还建议移动位于的列表 sitecore > Templates > User Defined > Lists > Content 在任何一个地方 sitecore > Content 要么 sitecore > System (无论哪个更有意义) 更新:尝试在课程上方添加以下内容: [SitecoreType(AutoMap ...
  • 这通常是通过视图顶部的inherits指令完成的: @using Glass.Mapper.Sc.Web.Mvc @inherits GlassView 然后在页面上,您可以正常使用您的模型; 如果对于某种情况,您希望使标题页面编辑器更加友好 - 那么您可以使用以下构造来访问模型属性: @Editable(x=>x.Title) This usually is done via inherits directive at the top of your view: @using ...
  • Model.Item == Context.Item? 正如@ Jim-Noellsch所提到的,如果您的代码基于当前上下文项运行,则默认值将与Model.Item相同。 但是,如果要构建数据源驱动的组件或使用控制器更改模型上的绑定项,则需要使用Model.Item来确保拉出绑定到模型的项,而不是上下文项。 MVC布局中的Web窗体? 至于MVC布局中的Web表单,我不相信Sitecore支持开箱即用。 您可以查看其他人为完成类似操作而做的一些自定义( Web表单中的MVC )。 从本质上讲,这归结为自定义 ...
  • 你可以在你看来: @using Sitecore.Mvc.Presentation @using Sitecore.Mvc @model RenderingModel @Html.Sitecore().Field("Title")
    @Html.Sitecore().Field("Image")
    @Html.Sitecore().Field("Text")
    you can have in your view: @using Sitecore.Mvc.Presentati ...
  • IgnoreUrlPrefixes设置应该处理这个。 只需在那里添加路由前缀,Sitecore就应该忽略它。 更多信息在这里 http://www.sitecore.net/learn/blogs/technical-blogs/john-west-sitecore-blog/posts/2012/06/four-ways-to-process-mvc-requests-wi ...
  • 我不推荐它,但您可以在@ {}中查看它 @{ var item = Sitecore.Context.Database.GetItem("/sitecore/content/home"); } 您应该真正转移到Sitecore控制器渲染并在控制器中执行此操作并将Item作为模型返回。 public class YourController : Controller { public ActionResult Stuff() { va ...
  • 谢谢大家的指导。 我已经弄清楚我怎么能得到我想要的东西。 我必须留在Sitecore管道中,所以我决定使用querystrings来实现这个目标。 这完美地解决了。 我使用我的Searchbox帖子操作重定向到具有控制器渲染的搜索页面。 Thank you all for your ansers. I have figured out how I could get what I wanted. I had to remain within the Sitecore pipeline so I decide ...
  • 这是Sitecore的正常行为。 原因是因为基本模板中引用了相同的模板。 因此,在渲染项目时,Sitecore将看到模板已经渲染,并且不会再渲染它。 如果模板A具有基础模板X而X具有基础模板Y,则模板A也不可能具有Y作为基础模板。 A => X X => Y which means A => Y 要允许显示2个富文本,您可以执行以下操作: 创建基本样式上下文 在模板样式上下文中,在“构建器”选项卡中添加“富文本”类型的“内容字段”,然后在“内容”选项卡中添加“基本样式”模板。 在Global Alert模 ...
  • 这是Glass Mapper的一个已知问题,已修复: https://github.com/mikeedwards83/Glass.Mapper/issues/100 您应该更新到最新的Glass Mapper版本以摆脱这个问题。 This is a known issue from Glass Mapper and has been fixed: https://github.com/mikeedwards83/Glass.Mapper/issues/100 You should update to th ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)