English 中文(简体)
清洁法典、无国籍人会议
原标题:Clean code, stateless session beans and private state

根据Robert C. Martin方法的清洁法,应当有小的签字。 最好的情况是完全没有参数的方法。 相反,建议使用国家变量。 这确实是有益的。 但关于无国籍问题的会议是谁?

这一名称是混淆不清的,因为SLSB可以说出。 你只得做家事,这样你就不使用以前欧洲法院联盟发出的呼吁。

回到清洁法: 我也热爱使用SLSB中的典型变量。 如果你仔细研究,那就没有遇到国家不一致的问题,因为国家不按每一种公开方法进行书写。

迄今情况良好。 但是,如果使用过的灯塔回池,会发生什么情况? 它这样做。 视国家规模而定,这可能是一种真正的记忆泄露。 JBoss非常慷慨地与大豆打交道,产生大量燃烧,造成一些严重的记忆消耗——根本就没有。

因此,一种办法是,先清理国家,然后才能找到好友,然后将养蜂归还给池。 但我认为,这似乎像应该避免的无用守则。

是否有适当办法处理这一问题? 这种状况的最佳做法是什么?

问题回答

• 保持生命简单,只停留在参数上。 即便是can,也从无国籍的EJB 你的用意中明显看出:shouldn t。

FWIW aiming for a goal of zero parameters seems silly to me. Aim for few, yes, but striving for zero for its own sake is just daft.

尽可能保持SLSB的变数,因为你不使用代理的确在方法之间发出呼吁。 例如:

@Stateless 
public class MyEJB {
    private String myVar;

    public void receiveVar(String myVar) {
        this.myVar = myVar;
        useVar();
    }

    private void useVar() {
        // do something with var
    }
}

问题在于:当你在另一个地方注入这一特别司法理事会时,任何方法的电话都将通过代理人实现实际的欧洲司法理事会。 因此,考虑到在要求代理人时,实际案件从集合中取回,因此没有保证代理人在两条或两条以上电话之间使用同样的集合。 因此无法确保任何申报的类别属性的价值。

当SLSB回到该集合时,它本身要承担每个固定价值(我认为,供应商可能会变换,我并不真的确定)。 但是,集中的SLSB案件已经具有先前组合的属性价值,这是完全可能的(也是可以接受的)。

我不理解你在这里的话:

So far so good. But what happens if a used bean goes back to the pool? It takes its state with it. Depending on the size of the state this could be a real memory leak. JBoss is very generous with beans and generates quite a bunch of them causing some serious memory consumption - for nothing.

你们是否有任何“大邦”的例子,在高等专业学校中你可以有?

最后:

我认为,处理这些价值观的最佳方式总是处理你所使用的国家变量。 在使用之前和之后进行清理。 最佳做法是避免这种混乱局面。

希望会有所帮助。

according to clean code by Robert C. Martin methods should have a small signature.

通常,在(转让物体)作为论据的情况下,这样一来就可以改变在不影响方法签字的情况下的原样。

而且,我更希望通过一个接口,而不是实际基级。

public void doSomething(IMyTransferObject arg){
 ...
}

界面

interface IMyTransferObject {
   ...
}

class TransferObject implements IMyTransferObject{
  private String name;
  private String game;
  ... accessor / mutator
}

The best case would be a method with no parameters at all. Instead it is recommended to use state variables. This is really usefull. But what about stateless session beans?

这不能以宗教方式加以遵循,而实际上没有理由这样做。

http://docs.oracle.com/javaee/6/tutorial/doc/gipjg.html” rel=“nofollow” http://docs.oracle.com/javaee/6/tutorial/doc/gipjg.html:

无国籍者

A stateless session bean does not maintain a conversational state with the client. When a client invokes the methods of a stateless bean, the bean’s instance variables may contain a state specific to that client but only for the duration of the invocation. When the method is finished, the client-specific state should not be retained. Clients may, however, change the state of instance variables in pooled stateless beans, and this state is held over to the next invocation of the pooled stateless bean. Except during method invocation, all instances of a stateless bean are equivalent, allowing the EJB container to assign an instance to any client. That is, the state of a stateless session bean should apply across all clients.

我不是EE的一位专家,但从技术上来说,这让我也能够利用田地规划。

我假定,你,以确保每条新方法的电话都更新,而且我认为你 should确保你在方法结束后删除提及内容,以确保你不会阻止旧物体的垃圾收集,因为有些“旧的”豆类仍然保留在某些池里。

我建议这样的模式:

public class MyBean{

  private SomeClass firstObject;
  private SomeOtherClass anotherObject;
  private AndAnotherClass thirdObject;

  public void theMethod(firstObject, anotherObject, thirdObject){
    try {
      this.firstObject = firstObject;
      this.anotherObject = anotherObject;
      this.third = thirdObject;

      startProcessing();

    }finally {
      this.firstObject = null;
      this.anotherObject = null;
      this.third = null;
    }
  }

  private void startProcessing() {
    doStep1();
    doStep2();
    doStep3();
  }

  [...]
}

仍然有许多法典——但如果你坚持这种风格,你就会自动跳出“Method”部分,并继续在“Processing”上读,你在“Processing”上做了一切明确而没有参数。





相关问题
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 ...

热门标签