小编his*_*art的帖子

我的单身人士可以被多次叫

我已经基于c ++ 11实现了单例。但是在某些情况下,可以多次调用构造函数。

该类将编译为静态lib,并由其他so lib(一个以上so lib)使用。并且该系统是多线程系统(在Android HAL级别运行)

/// .h文件:

class Logger
{
public:

    /// Return the singleton instance of Logger
    static Logger& GetInstance() {
        static Logger s_loggerSingleton;
        return s_loggerSingleton;
    }

private:

    /// Constructor
    Logger();
    /// Destructor
    ~Logger();
}
Run Code Online (Sandbox Code Playgroud)

/// .cpp文件

Logger::Logger()
{
   ALOGE("OfflineLogger create");
}

Logger::~Logger()
{

}
Run Code Online (Sandbox Code Playgroud)

应该创建一次,例如:

03-21 01:52:20.785   728  4522 E         : OfflineLogger create
Run Code Online (Sandbox Code Playgroud)

但是我可以看到它已经创建了不止一次

03-21 01:52:20.785   728  4522 E         : OfflineLogger create
03-21 01:52:20.863   728  2274 E         : OfflineLogger create
03-21 01:52:20.977   728  2273 E         : …
Run Code Online (Sandbox Code Playgroud)

c++ singleton android hal

30
推荐指数
1
解决办法
3788
查看次数

使用spring框架将Java对象中的顺序保留到json

我创建了一个Java Spring MVC Web应用程序,它提供了简单的静态服务。我有这样的对象类。

public class CreateEventWrapper {

    private String Topic;
    private String SubscriptionReference;
    private Date UtcTime;
    private List<Message> Messages;
    ...
}

public class Message {

    private List<Source> Source;
    ...
}

public class Source {

    private String Name;
    private String Value;
    ...
}
Run Code Online (Sandbox Code Playgroud)

控制器:

...
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(produces = "application/json")
class EventController {

    @RequestMapping(value = "/event", method = RequestMethod.POST)
    public ResponseEntity<CreateEventWrapper> CreateEvent(@RequestBody CreateEventWrapper eventWrapper) { …
Run Code Online (Sandbox Code Playgroud)

java rest spring json spring-mvc

3
推荐指数
1
解决办法
2423
查看次数

标签 统计

android ×1

c++ ×1

hal ×1

java ×1

json ×1

rest ×1

singleton ×1

spring ×1

spring-mvc ×1