如何在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
最满意答案
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.
相关问答
更多-
Sitecore和ASP.net MVC(Sitecore and ASP.net MVC)[2023-12-13]
在某些情况下,合并这两者可能会带来巨大好处。 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 ... -
Sitecore MVC Model.Item(Sitecore MVC Model.Item)[2024-03-01]
Model.Item == Context.Item? 正如@ Jim-Noellsch所提到的,如果您的代码基于当前上下文项运行,则默认值将与Model.Item相同。 但是,如果要构建数据源驱动的组件或使用控制器更改模型上的绑定项,则需要使用Model.Item来确保拉出绑定到模型的项,而不是上下文项。 MVC布局中的Web窗体? 至于MVC布局中的Web表单,我不相信Sitecore支持开箱即用。 您可以查看其他人为完成类似操作而做的一些自定义( Web表单中的MVC )。 从本质上讲,这归结为自定义 ... -
Sitecore MVC,Controller访问项目字段而不创建模型(Sitecore MVC, Controller accessing item fields without creating a model)[2024-03-26]
你可以在你看来: @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项(Returning a sitecore item with populated model from controller action)[2022-09-03]
谢谢大家的指导。 我已经弄清楚我怎么能得到我想要的东西。 我必须留在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 ...